Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(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');
})();
assert.throws(function() {
var buf = new SlowBuffer(8);
buf.readFloatLE(0xffffffff);
}, /Trying to read beyond buffer length/);
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);
});
assert.throws(() => SlowBuffer(len).toString('utf8'));
assert.throws(() => Buffer.alloc(len).toString('utf8'));
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;
}
['ucs2', 'ucs-2', 'utf16le', 'utf-16le'].forEach(function(encoding) {
var b = new SlowBuffer(10);
b.write('あいうえお', encoding);
assert.equal(b.toString(encoding), 'あいうえお');
});
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),
SafeBuffer.allocUnsafeSlow = function (size) {
if (typeof size !== 'number') {
throw new TypeError('Argument must be a number')
}
return buffer.SlowBuffer(size)
}
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();
}
Type.__reset = function (size) {
debug('resetting type buffer to %d', size);
TAP.buf = new buffer.SlowBuffer(size);
};