How to use the buffer.SlowBuffer 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 node-app / Nodelike / Nodelike Tests / package / test-buffer.js View on Github external
(function() {
  var buf = new Buffer('0123456789');
  assert.equal(buf.slice(-10, 10), '0123456789');
  assert.equal(buf.slice(-20, 10), '0123456789');
  assert.equal(buf.slice(-20, -10), '');
  assert.equal(buf.slice(0, -1), '012345678');
  assert.equal(buf.slice(2, -2), '234567');
  assert.equal(buf.slice(0, 65536), '0123456789');
  assert.equal(buf.slice(65536, 0), '');
  for (var i = 0, s = buf.toString(); i < buf.length; ++i) {
    assert.equal(buf.slice(-i), s.slice(-i));
    assert.equal(buf.slice(0, -i), s.slice(0, -i));
  }
  // try to slice a zero length Buffer
  // see https://github.com/joyent/node/issues/5881
  SlowBuffer(0).slice(0, 1);
  // make sure a zero length slice doesn't set the .parent attribute
  assert.equal(Buffer(5).slice(0,0).parent, undefined);
  // and make sure a proper slice does have a parent
  assert.ok(typeof Buffer(5).slice(0, 5).parent === 'object');
})();
github graalvm / graaljs / test / simple / test-buffer.js View on Github external
assert.throws(function() {
  var buf = new SlowBuffer(8);
  buf.readFloatLE(0xffffffff);
}, /Trying to read beyond buffer length/);
github jxcore / jxcore / test / simple / test-buffer.js View on Github external
assert.doesNotThrow(function() {
  var slow = new SlowBuffer(1);
  assert(slow.write('', Buffer.poolSize * 10) === 0);
  var fast = new Buffer(1);
  assert(fast.write('', Buffer.poolSize * 10) === 0);
});
github nodejs / abi-stable-node / test / parallel / test-buffer-regression-649.js View on Github external
assert.throws(() => SlowBuffer(len).toString('utf8'));
assert.throws(() => Buffer.alloc(len).toString('utf8'));
github graalvm / graaljs / test / simple / test-buffer.js View on Github external
function buildSlowBuffer(data) {
  if (Array.isArray(data)) {
    var buffer = new SlowBuffer(data.length);
    data.forEach(function(v, k) {
      buffer[k] = v;
    });
    return buffer;
  }
  return null;
}
github graalvm / graaljs / test / simple / test-buffer.js View on Github external
['ucs2', 'ucs-2', 'utf16le', 'utf-16le'].forEach(function(encoding) {
  var b = new SlowBuffer(10);
  b.write('あいうえお', encoding);
  assert.equal(b.toString(encoding), 'あいうえお');
});
github graalvm / graaljs / test / parallel / test-buffer-inspect.js View on Github external
let b = Buffer.allocUnsafe(4);
b.fill('1234');

let s = buffer.SlowBuffer(4);
s.fill('1234');

let expected = '';

assert.strictEqual(util.inspect(b), expected);
assert.strictEqual(util.inspect(s), expected);

b = Buffer.allocUnsafe(2);
b.fill('12');

s = buffer.SlowBuffer(2);
s.fill('12');

expected = '';

assert.strictEqual(util.inspect(b), expected);
assert.strictEqual(util.inspect(s), expected);

buffer.INSPECT_MAX_BYTES = Infinity;

assert.strictEqual(util.inspect(b), expected);
assert.strictEqual(util.inspect(s), expected);

b.inspect = undefined;
b.prop = new Uint8Array(0);
assert.strictEqual(
  util.inspect(b),
github pmq20 / node-packer / node / deps / npm / node_modules / safe-buffer / index.js View on Github external
SafeBuffer.allocUnsafeSlow = function (size) {
  if (typeof size !== 'number') {
    throw new TypeError('Argument must be a number')
  }
  return buffer.SlowBuffer(size)
}
github GPBeta / nc.js / src / native / fs.js View on Github external
var size = context.size = st.isFile() ? st.size : 0;

  if (size === 0) {
    context.buffers = [];
    context.read();
    return;
  }

  if (size > kMaxLength) {
    err = new RangeError('File size is greater than possible Buffer: ' +
                         `0x${kMaxLength.toString(16)} bytes`);
    return context.close(err);
  }

  context.buffer = new SlowBuffer(size);
  context.read();
}
github mtth / avsc / packages / types / lib / types.js View on Github external
Type.__reset = function (size) {
  debug('resetting type buffer to %d', size);
  TAP.buf = new buffer.SlowBuffer(size);
};