How to use the buffer.Buffer function in buffer

To help you get started, we’ve selected a few buffer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github graalvm / graaljs / test / simple / test-buffer.js View on Github external
expected.slice(240, 300) + '\x03' +
                      expected.slice(300, 360);
b = new Buffer(expectedIllegal, 'base64');
assert.equal(quote.length, b.length);
assert.equal(quote, b.toString('ascii', 0, quote.length));


assert.equal(new Buffer('', 'base64').toString(), '');
assert.equal(new Buffer('K', 'base64').toString(), '');

// multiple-of-4 with padding
assert.equal(new Buffer('Kg==', 'base64').toString(), '*');
assert.equal(new Buffer('Kio=', 'base64').toString(), '**');
assert.equal(new Buffer('Kioq', 'base64').toString(), '***');
assert.equal(new Buffer('KioqKg==', 'base64').toString(), '****');
assert.equal(new Buffer('KioqKio=', 'base64').toString(), '*****');
assert.equal(new Buffer('KioqKioq', 'base64').toString(), '******');
assert.equal(new Buffer('KioqKioqKg==', 'base64').toString(), '*******');
assert.equal(new Buffer('KioqKioqKio=', 'base64').toString(), '********');
assert.equal(new Buffer('KioqKioqKioq', 'base64').toString(), '*********');
assert.equal(new Buffer('KioqKioqKioqKg==', 'base64').toString(),
             '**********');
assert.equal(new Buffer('KioqKioqKioqKio=', 'base64').toString(),
             '***********');
assert.equal(new Buffer('KioqKioqKioqKioq', 'base64').toString(),
             '************');
assert.equal(new Buffer('KioqKioqKioqKioqKg==', 'base64').toString(),
             '*************');
assert.equal(new Buffer('KioqKioqKioqKioqKio=', 'base64').toString(),
             '**************');
assert.equal(new Buffer('KioqKioqKioqKioqKioq', 'base64').toString(),
             '***************');
github mendersoftware / gui / node_modules / vinyl-fs / node_modules / readable-stream / lib / _stream_readable.js View on Github external
if (n < list[0].length) {
      // just take a part of the first list item.
      // slice is the same for buffers and strings.
      var buf = list[0];
      ret = buf.slice(0, n);
      list[0] = buf.slice(n);
    } else if (n === list[0].length) {
      // first list is a perfect match
      ret = list.shift();
    } else {
      // complex case.
      // we have enough to cover it, but it spans past the first buffer.
      if (stringMode)
        ret = '';
      else
        ret = new Buffer(n);

      var c = 0;
      for (var i = 0, l = list.length; i < l && c < n; i++) {
        var buf = list[0];
        var cpy = Math.min(n - c, buf.length);

        if (stringMode)
          ret += buf.slice(0, cpy);
        else
          buf.copy(ret, c, 0, cpy);

        if (cpy < buf.length)
          list[0] = buf.slice(cpy);
        else
          list.shift();
github fictorial / redis-node-client / lib / redis-client.js View on Github external
self.onReply.call(self.thisArg, reply);
            }
            self.clearState();
            self.skip = 1; // Skip LF
        };

        switch (inbound[i]) {
        case CR:
            switch (this.type) {
                case INLINE:
                case ERROR:
                    // CR denotes end of the inline/error value.  
                    // +OK\r\n
                    //    ^

                    var inlineBuf = new Buffer(this.valueBufferLen);
                    this.valueBuffer.copy(inlineBuf, 0, 0, this.valueBufferLen);
                    maybeCallbackWithReply({ type:this.type, value:inlineBuf });
                    break;

                case INTEGER:
                    // CR denotes the end of the integer value.  
                    // :42\r\n
                    //    ^

                    var n = parseInt(this.valueBuffer.asciiSlice(0, this.valueBufferLen), 10);
                    maybeCallbackWithReply({ type:INTEGER, value:n });
                    break;

                case BULK:
                    if (this.bulkLengthExpected == null) {
                        // CR denotes end of first line of a bulk reply,
github jamesshore / automatopia / node_modules / browserify / node_modules / crypto-browserify / node_modules / browserify-sign / node_modules / parse-asn1 / node_modules / asn1.js / lib / asn1 / encoders / der.js View on Github external
// Bignum, assume big endian
  if (typeof num !== 'number' && !Buffer.isBuffer(num)) {
    var numArray = num.toArray();
    if (!num.sign && numArray[0] & 0x80) {
      numArray.unshift(0);
    }
    num = new Buffer(numArray);
  }

  if (Buffer.isBuffer(num)) {
    var size = num.length;
    if (num.length === 0)
      size++;

    var out = new Buffer(size);
    num.copy(out);
    if (num.length === 0)
      out[0] = 0
    return this._createEncoderBuffer(out);
  }

  if (num < 0x80)
    return this._createEncoderBuffer(num);

  if (num < 0x100)
    return this._createEncoderBuffer([0, num]);

  var size = 1;
  for (var i = num; i >= 0x100; i >>= 8)
    size++;
github icyphy / ptII / ptolemy / actor / lib / jjs / modules / iotAuth / iotAuth.js View on Github external
if (options.distributionKey !== null) {
                    console.log('Distribution key expired, requesting new distribution key as well...');
                } else {
                    console.log('No distribution key yet, requesting new distribution key as well...');
                }
                reqMsgType = msgType.SESSION_KEY_REQ_IN_PUB_ENC;
                sessionKeyReqBuf = serializeSessionKeyReq(sessionKeyReq);
                reqPayload = new buffer.Buffer(
                    crypto.publicEncryptAndSign(sessionKeyReqBuf.getArray(),
                        options.authPublicKey, options.entityPrivateKey,
                        options.publicKeyCryptoSpec.cipher, options.publicKeyCryptoSpec.sign));
            } else {
                console.log('distribution key available! ');
                reqMsgType = msgType.SESSION_KEY_REQ;
                sessionKeyReqBuf = serializeSessionKeyReq(sessionKeyReq);
                var encryptedSessionKeyReqBuf = new buffer.Buffer(
                    symmetricEncryptAuthenticate(sessionKeyReqBuf, options.distributionKey, options.distributionCryptoSpec));
                reqPayload = serializeSessionKeyReqWithDistributionKey(options.entityName,
                    encryptedSessionKeyReqBuf);
            }
            var toSend = exports.serializeIoTSP({
                msgType: reqMsgType,
                payload: reqPayload
            }).getArray();
            authClientSocket.send(toSend);
        } else {
            console.log('Session key response arrived.');
            handleSessionKeyResponse(options, obj, myNonce, sessionKeyResponseCallback, callbackParameters);
            authClientSocket.close();
        }
    });
    authClientSocket.on('close', function () {
github mapbox / tilelive / lib / tilelive / format.js View on Github external
function (err, json) {
                            if (err) return callback(err, null);
                             callback(null, [
                                new Buffer(JSON.stringify(json), 'utf8'),
                                { 'Content-Type': 'text/javascript; charset=utf-8' },
                                { keys: json.keys }
                            ]);
                        });
                } else {
github chjj / bpkg / lib / builtins / http.js View on Github external
return new Promise(function (resolve, reject) {
						if (self._destroyed) {
							reject()
						} else if(self.push(new Buffer(chunk))) {
							resolve()
						} else {
							self._resumeFetch = resolve
						}
					})
				},
github dstucrypt / jkurwa / lib / util / transport.js View on Github external
var transport_encode = function(documents, headers) {
    var rb = new Buffer(1024);

    if(headers) {
        rb = transport_header(rb, headers);
    }

    documents.map(function(el) {
        rb = write_buf(rb, el.type);
        rb = write_buf(rb,'\u0000');
        rb.writeUInt32LE(el.contents.length, rb._pos);
        rb._pos += 4;
        rb = write_buf(rb, el.contents);
    });
    return rb.slice(0, rb._pos);
};
github jaimehgb / RaiWebWallet / Wallet.js View on Github external
pad: function (dataBytes, nBytesPerBlock) {
	var nPaddingBytes = nBytesPerBlock - dataBytes.length % nBytesPerBlock;
	var zeroBytes = new Buffer(nPaddingBytes).fill(0x00);
	return Buffer.concat([ dataBytes, zeroBytes ]);
  },
github PunchThrough / bean-sdk-node / src / command-definitions.js View on Github external
_packReserved() {
    let buf = new buffer.Buffer(1)
    buf.writeUInt8(0, 0)
    return buf
  }