Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
assert.strictEqual(sb.buffer.byteLength, 4);
// should work without new
sb = SlowBuffer(4);
assert(sb instanceof Buffer);
assert.strictEqual(sb.length, 4);
sb.fill(1);
for (const [key, value] of sb.entries()) {
assert.deepStrictEqual(value, ones[key]);
}
// should work with edge cases
assert.strictEqual(SlowBuffer(0).length, 0);
try {
assert.strictEqual(
SlowBuffer(buffer.kMaxLength).length, buffer.kMaxLength);
} catch (e) {
assert.equal(e.message, common.engineSpecificMessage({
v8: 'Array buffer allocation failed',
chakracore: 'Invalid offset/length when creating typed array'
}));
}
// should work with number-coercible values
assert.strictEqual(SlowBuffer('6').length, 6);
assert.strictEqual(SlowBuffer(true).length, 1);
// should create zero-length buffer if parameter is not a number
assert.strictEqual(SlowBuffer().length, 0);
assert.strictEqual(SlowBuffer(NaN).length, 0);
assert.strictEqual(SlowBuffer({}).length, 0);
assert.strictEqual(SlowBuffer('string').length, 0);
'use strict';
const common = require('../common');
const assert = require('assert');
const buffer = require('buffer');
const SlowBuffer = buffer.SlowBuffer;
const kMaxLength = buffer.kMaxLength;
const bufferMaxSizeMsg = common.bufferMaxSizeMsg;
assert.throws(() => Buffer((-1 >>> 0) + 1), bufferMaxSizeMsg);
assert.throws(() => SlowBuffer((-1 >>> 0) + 1), bufferMaxSizeMsg);
assert.throws(() => Buffer.alloc((-1 >>> 0) + 1), bufferMaxSizeMsg);
assert.throws(() => Buffer.allocUnsafe((-1 >>> 0) + 1), bufferMaxSizeMsg);
assert.throws(() => Buffer.allocUnsafeSlow((-1 >>> 0) + 1), bufferMaxSizeMsg);
assert.throws(() => Buffer(kMaxLength + 1), bufferMaxSizeMsg);
assert.throws(() => SlowBuffer(kMaxLength + 1), bufferMaxSizeMsg);
assert.throws(() => Buffer.alloc(kMaxLength + 1), bufferMaxSizeMsg);
assert.throws(() => Buffer.allocUnsafe(kMaxLength + 1), bufferMaxSizeMsg);
assert.throws(() => Buffer.allocUnsafeSlow(kMaxLength + 1), bufferMaxSizeMsg);
// issue GH-4331
assert.throws(() => Buffer.allocUnsafe(0xFFFFFFFF), bufferMaxSizeMsg);
in: [tmpDir + 'test64m.bin'],
blockSize: 1048576,
blocks: 0,
singleFile: true
},
{
in: [tmpDir + 'test65k.bin'],
blockSize: 1048576,
blocks: 0,
singleFile: true
},*/
// 2x large block size test
{
in: [tmpDir + 'test64m.bin'],
blockSize: Math.floor((require('buffer').kMaxLength || (1024*1024*1024-1))/4)*4 - 192, // max allowable buffer size test
blocks: 1,
memory: process.arch == 'x64' ? '2.5g' : '1.5g',
singleFile: true
},
{
in: [tmpDir + 'test64m.bin'],
blockSize: 4294967296, // 4GB, should exceed node's limit
blocks: 2,
memory: '511m',
singleFile: true
},
{ // max number of blocks test
in: [tmpDir + 'test64m.bin'],
blockSize: 2048,
blocks: 32768, // max allowed by par2cmdline; TODO: test w/ 65536
singleFile: true
"use strict";
var emitter = require('events').EventEmitter;
var Par2 = require('./par2');
var async = require('async');
var fs = require('fs');
var path = require('path');
var writev = require('./writev');
var MAX_BUFFER_SIZE = (require('buffer').kMaxLength || (1024*1024*1024-1)) - 192; // the '-192' is padding to deal with alignment issues + 68-byte header
var MAX_WRITE_SIZE = 0x7ffff000; // writev is usually limited to 2GB - 4KB page?
// normalize path for comparison purposes; this is very different to node's path.normalize()
var pathNormalize;
if(path.sep == '\\') {
// assume Windows
pathNormalize = function(p) {
return p.replace(/\//g, '\\').toLowerCase();
};
} else {
pathNormalize = function(p) {
return p;
};
}
var allocBuffer = (Buffer.allocUnsafe || Buffer);
internalUtil.assertCrypto();
exports.DEFAULT_ENCODING = 'buffer';
const constants = process.binding('constants').crypto;
const binding = process.binding('crypto');
const randomBytes = binding.randomBytes;
const getCiphers = binding.getCiphers;
const getHashes = binding.getHashes;
const getCurves = binding.getCurves;
const getFipsCrypto = binding.getFipsCrypto;
const setFipsCrypto = binding.setFipsCrypto;
const timingSafeEqual = binding.timingSafeEqual;
const Buffer = require('buffer').Buffer;
const kBufferMaxLength = require('buffer').kMaxLength;
const stream = require('stream');
const util = require('util');
const { isUint8Array } = process.binding('util');
const LazyTransform = require('internal/streams/lazy_transform');
const DH_GENERATOR = 2;
Object.defineProperty(exports, 'constants', {
configurable: false,
enumerable: true,
value: constants
});
// This is here because many functions accepted binary strings without
// any explicit encoding in older versions of node, and we don't want
// to break them unnecessarily.
assert.throws(function() {
SlowBuffer(buffer.kMaxLength + 1);
}, expectedError);
const pathModule = require('path');
let binding = process.binding('fs');
const constants = require('constants');
const fs = exports;
const Buffer = require('buffer').Buffer;
const Stream = require('stream').Stream;
const EventEmitter = require('events');
const FSReqWrap = binding.FSReqWrap;
const FSEvent = process.binding('fs_event_wrap').FSEvent;
const Readable = Stream.Readable;
const Writable = Stream.Writable;
const kMinPoolSpace = 128;
const kMaxLength = require('buffer').kMaxLength;
const O_APPEND = constants.O_APPEND || 0;
const O_CREAT = constants.O_CREAT || 0;
const O_EXCL = constants.O_EXCL || 0;
const O_RDONLY = constants.O_RDONLY || 0;
const O_RDWR = constants.O_RDWR || 0;
const O_SYNC = constants.O_SYNC || 0;
const O_TRUNC = constants.O_TRUNC || 0;
const O_WRONLY = constants.O_WRONLY || 0;
const isWindows = process.platform === 'win32';
const DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG);
const errnoException = util._errnoException;
function throwOptionsError(options) {
const Buffer = buffer.Buffer;
const BigInt = require('big-integer');
const EventEmitter = require('events');
const SHA = require('jssha');
const util = require('util');
const msgpack = require('msgpack-lite');
/**
* .. note::
*
* This library will likely issue a warning over the size of data that :js:class:`Buffer` can hold. On most implementations
* of Javascript this is 2GiB, but the maximum size message that can be transmitted in our serialization scheme is 4GiB.
* This shouldn't be a problem for most applications, but you can discuss it in :issue:`83`.
*/
if (buffer.kMaxLength < 4294967299) {
console.warn(`This implementation of javascript does not support the maximum protocol length. The largest message you may receive is 4294967299 bytes, but you can only allocate ${buffer.kMaxLength}, or ${(buffer.kMaxLength / 4294967299 * 100).toFixed(2)}% of that.`);
}
var base;
if( typeof exports !== 'undefined' ) {
if( typeof module !== 'undefined' && module.exports ) {
base = exports = module.exports;
}
base = exports;
}
else {
root.base = {};
base = root;
}
/**
const internalUtil = require('internal/util');
const assertEncoding = internalFS.assertEncoding;
const stringToFlags = internalFS.stringToFlags;
const getPathFromURL = internalURL.getPathFromURL;
Object.defineProperty(exports, 'constants', {
configurable: false,
enumerable: true,
value: constants
});
const Readable = Stream.Readable;
const Writable = Stream.Writable;
const kMinPoolSpace = 128;
const kMaxLength = require('buffer').kMaxLength;
const isWindows = process.platform === 'win32';
const DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG);
const errnoException = util._errnoException;
function getOptions(options, defaultOptions) {
if (options === null || options === undefined ||
typeof options === 'function') {
return defaultOptions;
}
if (typeof options === 'string') {
defaultOptions = util._extend({}, defaultOptions);
defaultOptions.encoding = options;
options = defaultOptions;
var pathModule = require('path');
var binding = process.binding('fs_wrap');
var constants = require('constants');
var fs = exports;
var Buffer = require('buffer').Buffer;
var Stream = require('stream').Stream;
var EventEmitter = require('events');
var FSReqWrap = binding.FSReqWrap;
var FSEvent = process.binding('fs_event_wrap').FSEvent;
var Readable = Stream.Readable;
var Writable = Stream.Writable;
var kMinPoolSpace = 128;
var kMaxLength = require('buffer').kMaxLength;
var O_APPEND = constants.O_APPEND || 0;
var O_CREAT = constants.O_CREAT || 0;
var O_EXCL = constants.O_EXCL || 0;
var O_RDONLY = constants.O_RDONLY || 0;
var O_RDWR = constants.O_RDWR || 0;
var O_SYNC = constants.O_SYNC || 0;
var O_TRUNC = constants.O_TRUNC || 0;
var O_WRONLY = constants.O_WRONLY || 0;
var isWindows = process.platform === 'win32';
var DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG);
var errnoException = util._errnoException;
function throwOptionsError(options) {