Comparing version 3.2.2 to 3.3.0
#!/usr/bin/env node | ||
var concat = require('concat-stream') | ||
var fs = require('fs') | ||
var hyperquest = require('hyperquest') | ||
var concat = require('concat-stream') | ||
var cp = require('child_process') | ||
var split = require('split') | ||
var thru = require('through2') | ||
var fs = require('fs') | ||
var through = require('through2') | ||
var url = 'https://api.github.com/repos/iojs/io.js/contents' | ||
var url = 'https://api.github.com/repos/nodejs/io.js/contents' | ||
var dirs = [ | ||
@@ -15,2 +16,5 @@ '/test/parallel', | ||
cp.execSync('rm -r node/*.js', { cwd: __dirname + '/../test' }) | ||
cp.execSync('rm -r node-es6/*.js', { cwd: __dirname + '/../test' }) | ||
var httpOpts = { | ||
@@ -39,11 +43,13 @@ headers: { | ||
var path | ||
if (file.name !== 'test-buffer-iterator.js') { | ||
if (file.name === 'test-buffer-iterator.js') { | ||
path = __dirname + '/../test/node-es6/' + file.name | ||
} else if (file.name === 'test-buffer-fakes.js') { | ||
// These teses only apply to node, where they're calling into C++ and need to | ||
// ensure the prototype can't be faked, or else there will be a segfault. | ||
return | ||
} else { | ||
path = __dirname + '/../test/node/' + file.name | ||
} else { | ||
path = __dirname + '/../test/es6/' + file.name | ||
} | ||
var downloadUrl = file.download_url.replace('/master/', '/v1.x/') | ||
hyperquest(downloadUrl, httpOpts) | ||
hyperquest(file.download_url, httpOpts) | ||
.pipe(split()) | ||
@@ -58,3 +64,3 @@ .pipe(testfixer(file.name)) | ||
return thru(function (line, enc, cb) { | ||
return through(function (line, enc, cb) { | ||
line = line.toString() | ||
@@ -64,5 +70,6 @@ | ||
// require buffer explicitly | ||
line = 'var Buffer = require(\'../../\').Buffer\n' + | ||
'if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false\n' + | ||
line | ||
var preamble = 'var Buffer = require(\'../../\').Buffer;\n' + | ||
'if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false;' | ||
if (/use strict/.test(line)) line += '\n' + preamble | ||
else line + preamble + '\n' + line | ||
firstline = false | ||
@@ -72,3 +79,3 @@ } | ||
// comment out require('common') | ||
line = line.replace(/(var common = require.*)/, 'var common = {};') | ||
line = line.replace(/((var|const) common = require.*)/, 'var common = {};') | ||
@@ -79,3 +86,6 @@ // require browser buffer | ||
// smalloc is only used for kMaxLength | ||
line = line.replace(/require\('smalloc'\)/, '{ kMaxLength: 0x3FFFFFFF }') | ||
line = line.replace( | ||
/require\('smalloc'\)/, | ||
'{ kMaxLength: process.env.OBJECT_IMPL ? 0x3fffffff : 0x7fffffff }' | ||
) | ||
@@ -82,0 +92,0 @@ // comment out console logs |
72
index.js
@@ -17,3 +17,2 @@ /*! | ||
var kMaxLength = 0x3fffffff | ||
var rootParent = {} | ||
@@ -56,2 +55,8 @@ | ||
function kMaxLength () { | ||
return Buffer.TYPED_ARRAY_SUPPORT | ||
? 0x7fffffff | ||
: 0x3fffffff | ||
} | ||
/** | ||
@@ -207,5 +212,5 @@ * Class: Buffer | ||
// length is NaN (which is otherwise coerced to zero.) | ||
if (length >= kMaxLength) { | ||
if (length >= kMaxLength()) { | ||
throw new RangeError('Attempt to allocate Buffer larger than maximum ' + | ||
'size: 0x' + kMaxLength.toString(16) + ' bytes') | ||
'size: 0x' + kMaxLength().toString(16) + ' bytes') | ||
} | ||
@@ -302,25 +307,34 @@ return length | 0 | ||
function byteLength (string, encoding) { | ||
if (typeof string !== 'string') string = String(string) | ||
if (typeof string !== 'string') string = '' + string | ||
if (string.length === 0) return 0 | ||
var len = string.length | ||
if (len === 0) return 0 | ||
switch (encoding || 'utf8') { | ||
case 'ascii': | ||
case 'binary': | ||
case 'raw': | ||
return string.length | ||
case 'ucs2': | ||
case 'ucs-2': | ||
case 'utf16le': | ||
case 'utf-16le': | ||
return string.length * 2 | ||
case 'hex': | ||
return string.length >>> 1 | ||
case 'utf8': | ||
case 'utf-8': | ||
return utf8ToBytes(string).length | ||
case 'base64': | ||
return base64ToBytes(string).length | ||
default: | ||
return string.length | ||
// Use a for loop to avoid recursion | ||
var loweredCase = false | ||
for (;;) { | ||
switch (encoding) { | ||
case 'ascii': | ||
case 'binary': | ||
// Deprecated | ||
case 'raw': | ||
case 'raws': | ||
return len | ||
case 'utf8': | ||
case 'utf-8': | ||
return utf8ToBytes(string).length | ||
case 'ucs2': | ||
case 'ucs-2': | ||
case 'utf16le': | ||
case 'utf-16le': | ||
return len * 2 | ||
case 'hex': | ||
return len >>> 1 | ||
case 'base64': | ||
return base64ToBytes(string).length | ||
default: | ||
if (loweredCase) return utf8ToBytes(string).length // assume utf8 | ||
encoding = ('' + encoding).toLowerCase() | ||
loweredCase = true | ||
} | ||
} | ||
@@ -334,4 +348,3 @@ } | ||
// toString(encoding, start=0, end=buffer.length) | ||
Buffer.prototype.toString = function toString (encoding, start, end) { | ||
function slowToString (encoding, start, end) { | ||
var loweredCase = false | ||
@@ -379,2 +392,9 @@ | ||
Buffer.prototype.toString = function toString () { | ||
var length = this.length | 0 | ||
if (length === 0) return '' | ||
if (arguments.length === 0) return utf8Slice(this, 0, length) | ||
return slowToString.apply(this, arguments) | ||
} | ||
Buffer.prototype.equals = function equals (b) { | ||
@@ -381,0 +401,0 @@ if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') |
{ | ||
"name": "buffer", | ||
"description": "Node.js Buffer API, for the browser", | ||
"version": "3.2.2", | ||
"version": "3.3.0", | ||
"author": { | ||
@@ -28,6 +28,6 @@ "name": "Feross Aboukhadijeh", | ||
"is-nan": "^1.0.1", | ||
"split": "^0.3.2", | ||
"standard": "^3.6.1", | ||
"split": "^1.0.0", | ||
"standard": "^4.3.2", | ||
"tape": "^4.0.0", | ||
"through2": "^0.6.3", | ||
"through2": "^2.0.0", | ||
"zuul": "^3.0.0" | ||
@@ -55,3 +55,3 @@ }, | ||
"test-browser-local": "zuul --local -- test/*.js test/node/*.js", | ||
"test-node": "tape test/*.js test/node/*.js test/es6/*.js && OBJECT_IMPL=true tape test/*.js test/node/*.js", | ||
"test-node": "tape test/*.js test/node/*.js test/node-es6/*.js && OBJECT_IMPL=true tape test/*.js test/node/*.js", | ||
"perf": "browserify --debug perf/bracket-notation.js > perf/bundle.js && open perf/index.html", | ||
@@ -64,20 +64,7 @@ "perf-node": "node perf/bracket-notation.js && node perf/concat.js && node perf/copy-big.js && node perf/copy.js && node perf/new-big.js && node perf/new.js && node perf/readDoubleBE.js && node perf/readFloatBE.js && node perf/readUInt32LE.js && node perf/slice.js && node perf/writeFloatBE.js", | ||
"test/node/*.js", | ||
"test/es6/*.js", | ||
"test/node-es6/*.js", | ||
"test/_polyfill.js", | ||
"perf/*.js" | ||
] | ||
}, | ||
"testling": { | ||
"files": "test/*.js", | ||
"browsers": [ | ||
"ie/6..latest", | ||
"chrome/4..latest", | ||
"firefox/3..latest", | ||
"safari/5.1..latest", | ||
"opera/12.0..latest", | ||
"iphone/6", | ||
"ipad/6", | ||
"android-browser/latest" | ||
] | ||
} | ||
} |
@@ -1,1 +0,1 @@ | ||
io.js/node.js core buffer tests | ||
node core buffer tests |
@@ -1,3 +0,4 @@ | ||
var Buffer = require('../../').Buffer | ||
if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false | ||
'use strict'; | ||
var Buffer = require('../../').Buffer; | ||
if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false; | ||
var common = {}; | ||
@@ -4,0 +5,0 @@ var assert = require('assert'); |
@@ -1,3 +0,4 @@ | ||
var Buffer = require('../../').Buffer | ||
if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false | ||
'use strict'; | ||
var Buffer = require('../../').Buffer; | ||
if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false; | ||
var common = {}; | ||
@@ -7,6 +8,6 @@ var assert = require('assert'); | ||
// The tests below should throw an error, not abort the process... | ||
assert.throws(function() { new Buffer(0x3fffffff + 1) }, RangeError); | ||
// assert.throws(function() { new Int8Array(0x3fffffff + 1) }, RangeError); | ||
// assert.throws(function() { new ArrayBuffer(0x3fffffff + 1) }, RangeError); | ||
// assert.throws(function() { new Float64Array(0x7ffffff + 1) }, RangeError); | ||
assert.throws(function() { new Buffer(0x3fffffff + 1); }, RangeError); | ||
// assert.throws(function() { new Int8Array(0x3fffffff + 1); }, RangeError); | ||
// assert.throws(function() { new ArrayBuffer(0x3fffffff + 1); }, RangeError); | ||
// assert.throws(function() { new Float64Array(0x7ffffff + 1); }, RangeError); | ||
@@ -1,3 +0,4 @@ | ||
var Buffer = require('../../').Buffer | ||
if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false | ||
'use strict'; | ||
var Buffer = require('../../').Buffer; | ||
if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false; | ||
var common = {}; | ||
@@ -19,6 +20,6 @@ var assert = require('assert'); | ||
assert(flatOne === one[0]); | ||
assert(flatLong.toString() === (new Array(10+1).join('asdf'))); | ||
assert(flatLongLen.toString() === (new Array(10+1).join('asdf'))); | ||
assert(flatLong.toString() === (new Array(10 + 1).join('asdf'))); | ||
assert(flatLongLen.toString() === (new Array(10 + 1).join('asdf'))); | ||
// console.log("ok"); | ||
// console.log('ok'); | ||
@@ -1,3 +0,4 @@ | ||
var Buffer = require('../../').Buffer | ||
if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false | ||
'use strict'; | ||
var Buffer = require('../../').Buffer; | ||
if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false; | ||
var common = {}; | ||
@@ -4,0 +5,0 @@ var assert = require('assert'); |
@@ -1,3 +0,4 @@ | ||
var Buffer = require('../../').Buffer | ||
if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false | ||
'use strict'; | ||
var Buffer = require('../../').Buffer; | ||
if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false; | ||
var common = {}; | ||
@@ -40,1 +41,2 @@ var assert = require('assert'); | ||
}); | ||
@@ -1,3 +0,4 @@ | ||
var Buffer = require('../../').Buffer | ||
if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false | ||
'use strict'; | ||
var Buffer = require('../../').Buffer; | ||
if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false; | ||
var common = {}; | ||
@@ -12,4 +13,4 @@ var assert = require('assert'); | ||
buff, | ||
"slicedBufffer should have its parent set to the original " + | ||
" buffer"); | ||
'slicedBufffer should have its parent set to the original ' + | ||
' buffer'); | ||
@@ -1,3 +0,4 @@ | ||
var Buffer = require('../../').Buffer | ||
if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false | ||
'use strict'; | ||
var Buffer = require('../../').Buffer; | ||
if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false; | ||
var common = {}; | ||
@@ -8,3 +9,3 @@ var assert = require('assert'); | ||
var SlowBuffer = require('../../').SlowBuffer; | ||
var smalloc = { kMaxLength: 0x3FFFFFFF }; | ||
var smalloc = { kMaxLength: process.env.OBJECT_IMPL ? 0x3fffffff : 0x7fffffff }; | ||
@@ -133,4 +134,4 @@ // counter to ensure unique value is always copied | ||
} | ||
for (var i = Math.floor(c.length /2) + 1; i < c.length; i++) { | ||
assert.strictEqual(c[c.length-1], c[i]); | ||
for (var i = Math.floor(c.length / 2) + 1; i < c.length; i++) { | ||
assert.strictEqual(c[c.length - 1], c[i]); | ||
} | ||
@@ -275,36 +276,51 @@ | ||
// ASCII slice test | ||
var asciiString = 'hello world'; | ||
var offset = 100; | ||
for (var j = 0; j < 500; j++) { | ||
for (var i = 0; i < asciiString.length; i++) { | ||
b[i] = asciiString.charCodeAt(i); | ||
} | ||
var asciiSlice = b.toString('ascii', 0, asciiString.length); | ||
assert.equal(asciiString, asciiSlice); | ||
for (var i = 0; i < asciiString.length; i++) { | ||
b[i] = asciiString.charCodeAt(i); | ||
} | ||
var asciiSlice = b.toString('ascii', 0, asciiString.length); | ||
assert.equal(asciiString, asciiSlice); | ||
var written = b.write(asciiString, offset, 'ascii'); | ||
assert.equal(asciiString.length, written); | ||
var asciiSlice = b.toString('ascii', offset, offset + asciiString.length); | ||
assert.equal(asciiString, asciiSlice); | ||
var written = b.write(asciiString, offset, 'ascii'); | ||
assert.equal(asciiString.length, written); | ||
var asciiSlice = b.toString('ascii', offset, offset + asciiString.length); | ||
assert.equal(asciiString, asciiSlice); | ||
var sliceA = b.slice(offset, offset + asciiString.length); | ||
var sliceB = b.slice(offset, offset + asciiString.length); | ||
for (var i = 0; i < asciiString.length; i++) { | ||
assert.equal(sliceA[i], sliceB[i]); | ||
} | ||
// TODO utf8 slice tests | ||
var sliceA = b.slice(offset, offset + asciiString.length); | ||
var sliceB = b.slice(offset, offset + asciiString.length); | ||
for (var i = 0; i < asciiString.length; i++) { | ||
assert.equal(sliceA[i], sliceB[i]); | ||
} | ||
// UTF-8 slice test | ||
for (var j = 0; j < 100; j++) { | ||
var slice = b.slice(100, 150); | ||
assert.equal(50, slice.length); | ||
for (var i = 0; i < 50; i++) { | ||
assert.equal(b[100 + i], slice[i]); | ||
} | ||
var utf8String = '¡hέlló wôrld!'; | ||
var offset = 100; | ||
b.write(utf8String, 0, Buffer.byteLength(utf8String), 'utf8'); | ||
var utf8Slice = b.toString('utf8', 0, Buffer.byteLength(utf8String)); | ||
assert.equal(utf8String, utf8Slice); | ||
var written = b.write(utf8String, offset, 'utf8'); | ||
assert.equal(Buffer.byteLength(utf8String), written); | ||
utf8Slice = b.toString('utf8', offset, offset + Buffer.byteLength(utf8String)); | ||
assert.equal(utf8String, utf8Slice); | ||
var sliceA = b.slice(offset, offset + Buffer.byteLength(utf8String)); | ||
var sliceB = b.slice(offset, offset + Buffer.byteLength(utf8String)); | ||
for (var i = 0; i < Buffer.byteLength(utf8String); i++) { | ||
assert.equal(sliceA[i], sliceB[i]); | ||
} | ||
var slice = b.slice(100, 150); | ||
assert.equal(50, slice.length); | ||
for (var i = 0; i < 50; i++) { | ||
assert.equal(b[100 + i], slice[i]); | ||
} | ||
// make sure only top level parent propagates from allocPool | ||
@@ -325,3 +341,2 @@ var b = new Buffer(5); | ||
// Bug regression test | ||
@@ -569,11 +584,2 @@ var testValue = '\u00F6\u65E5\u672C\u8A9E'; // ö日本語 | ||
// byte length | ||
assert.equal(14, Buffer.byteLength('Il était tué')); | ||
assert.equal(14, Buffer.byteLength('Il était tué', 'utf8')); | ||
['ucs2', 'ucs-2', 'utf16le', 'utf-16le'].forEach(function(encoding) { | ||
assert.equal(24, Buffer.byteLength('Il était tué', encoding)); | ||
}); | ||
assert.equal(12, Buffer.byteLength('Il était tué', 'ascii')); | ||
assert.equal(12, Buffer.byteLength('Il était tué', 'binary')); | ||
// slice(0,0).length === 0 | ||
@@ -853,3 +859,3 @@ assert.equal(0, Buffer('hello').slice(0, 0).length); | ||
// GH-5110 | ||
(function () { | ||
(function() { | ||
var buffer = new Buffer('test'), | ||
@@ -1079,3 +1085,3 @@ string = JSON.stringify(buffer); | ||
// make sure a zero length slice doesn't set the .parent attribute | ||
assert.equal(Buffer(5).slice(0,0).parent, undefined); | ||
assert.equal(Buffer(5).slice(0, 0).parent, undefined); | ||
// and make sure a proper slice does have a parent | ||
@@ -1085,6 +1091,2 @@ assert.ok(typeof Buffer(5).slice(0, 5).parent === 'object'); | ||
// Make sure byteLength properly checks for base64 padding | ||
assert.equal(Buffer.byteLength('aaa=', 'base64'), 2); | ||
assert.equal(Buffer.byteLength('aaaa==', 'base64'), 3); | ||
// Regression test for #5482: should throw but not assert in C++ land. | ||
@@ -1100,3 +1102,3 @@ assert.throws(function() { | ||
for (var i = 0; i < 7; ++i) a = a.concat(a); | ||
a = a.map(function(_, i) { return i }); | ||
a = a.map(function(_, i) { return i; }); | ||
var b = Buffer(a); | ||
@@ -1114,7 +1116,7 @@ var c = Buffer(b); | ||
assert.throws(function () { | ||
assert.throws(function() { | ||
new Buffer(smalloc.kMaxLength + 1); | ||
}, RangeError); | ||
assert.throws(function () { | ||
assert.throws(function() { | ||
new SlowBuffer(smalloc.kMaxLength + 1); | ||
@@ -1187,3 +1189,3 @@ }, RangeError); | ||
// Regression test for https://github.com/iojs/io.js/issues/649. | ||
// Regression test for https://github.com/nodejs/io.js/issues/649. | ||
assert.throws(function() { Buffer(1422561062959).toString('utf8'); }); | ||
@@ -1190,0 +1192,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
133609
32
3432
24
2