Comparing version 2.4.0 to 2.5.0
@@ -18,12 +18,24 @@ require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({"Focm2+":[function(require,module,exports){ | ||
/** | ||
* If `Buffer._useTypedArrays`: | ||
* If `TYPED_ARRAY_SUPPORT`: | ||
* === true Use Uint8Array implementation (fastest) | ||
* === false Use Object implementation (compatible down to IE6) | ||
* === false Use Object implementation (most compatible, even IE6) | ||
* | ||
* Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, | ||
* Opera 11.6+, iOS 4.2+. | ||
* | ||
* Note: | ||
* | ||
* - Implementation must support adding new properties to `Uint8Array` instances. | ||
* Firefox 4-29 lacked support, fixed in Firefox 30+. | ||
* See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438. | ||
* | ||
* - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function. | ||
* | ||
* - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of | ||
* incorrect length in some situations. | ||
* | ||
* We detect these buggy browsers and set `TYPED_ARRAY_SUPPORT` to `false` so they will | ||
* get the Object implementation, which is slower but will work correctly. | ||
*/ | ||
Buffer._useTypedArrays = (function () { | ||
// Detect if browser supports Typed Arrays. Supported browsers are IE 10+, Firefox 4+, | ||
// Chrome 7+, Safari 5.1+, Opera 11.6+, iOS 4.2+. If the browser does not support adding | ||
// properties to `Uint8Array` instances, then that's the same as no `Uint8Array` support | ||
// because we need to be able to add all the node Buffer API methods. This is an issue | ||
// in Firefox 4-29. Now fixed: https://bugzilla.mozilla.org/show_bug.cgi?id=695438 | ||
var TYPED_ARRAY_SUPPORT = (function () { | ||
try { | ||
@@ -33,4 +45,5 @@ var buf = new ArrayBuffer(0) | ||
arr.foo = function () { return 42 } | ||
return 42 === arr.foo() && | ||
typeof arr.subarray === 'function' // Chrome 9-10 lack `subarray` | ||
return 42 === arr.foo() && // typed array instances can be augmented | ||
typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray` | ||
new Uint8Array(1).subarray(1, 1).byteLength === 0 // ie10 has broken `subarray` | ||
} catch (e) { | ||
@@ -68,3 +81,3 @@ return false | ||
} else if (type === 'object' && subject !== null) { // assume object is array-like | ||
if (subject.type === 'Buffer' && Array.isArray(subject.data)) | ||
if (subject.type === 'Buffer' && isArray(subject.data)) | ||
subject = subject.data | ||
@@ -76,3 +89,3 @@ length = +subject.length > 0 ? Math.floor(+subject.length) : 0 | ||
var buf | ||
if (Buffer._useTypedArrays) { | ||
if (TYPED_ARRAY_SUPPORT) { | ||
// Preferred: Return an augmented `Uint8Array` instance for best performance | ||
@@ -88,3 +101,3 @@ buf = Buffer._augment(new Uint8Array(length)) | ||
var i | ||
if (Buffer._useTypedArrays && typeof subject.byteLength === 'number') { | ||
if (TYPED_ARRAY_SUPPORT && typeof subject.byteLength === 'number') { | ||
// Speed optimization -- use set if we're copying from a typed array | ||
@@ -103,3 +116,3 @@ buf._set(subject) | ||
buf.write(subject, 0, encoding) | ||
} else if (type === 'number' && !Buffer._useTypedArrays && !noZero) { | ||
} else if (type === 'number' && !TYPED_ARRAY_SUPPORT && !noZero) { | ||
for (i = 0; i < length; i++) { | ||
@@ -411,3 +424,3 @@ buf[i] = 0 | ||
if (len < 100 || !Buffer._useTypedArrays) { | ||
if (len < 100 || !TYPED_ARRAY_SUPPORT) { | ||
for (var i = 0; i < len; i++) { | ||
@@ -506,3 +519,3 @@ target[i + target_start] = this[i + start] | ||
if (Buffer._useTypedArrays) { | ||
if (TYPED_ARRAY_SUPPORT) { | ||
return Buffer._augment(this.subarray(start, end)) | ||
@@ -966,3 +979,3 @@ } else { | ||
if (typeof Uint8Array !== 'undefined') { | ||
if (Buffer._useTypedArrays) { | ||
if (TYPED_ARRAY_SUPPORT) { | ||
return (new Buffer(this)).buffer | ||
@@ -969,0 +982,0 @@ } else { |
47
index.js
@@ -17,12 +17,24 @@ /*! | ||
/** | ||
* If `Buffer._useTypedArrays`: | ||
* If `TYPED_ARRAY_SUPPORT`: | ||
* === true Use Uint8Array implementation (fastest) | ||
* === false Use Object implementation (compatible down to IE6) | ||
* === false Use Object implementation (most compatible, even IE6) | ||
* | ||
* Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, | ||
* Opera 11.6+, iOS 4.2+. | ||
* | ||
* Note: | ||
* | ||
* - Implementation must support adding new properties to `Uint8Array` instances. | ||
* Firefox 4-29 lacked support, fixed in Firefox 30+. | ||
* See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438. | ||
* | ||
* - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function. | ||
* | ||
* - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of | ||
* incorrect length in some situations. | ||
* | ||
* We detect these buggy browsers and set `TYPED_ARRAY_SUPPORT` to `false` so they will | ||
* get the Object implementation, which is slower but will work correctly. | ||
*/ | ||
Buffer._useTypedArrays = (function () { | ||
// Detect if browser supports Typed Arrays. Supported browsers are IE 10+, Firefox 4+, | ||
// Chrome 7+, Safari 5.1+, Opera 11.6+, iOS 4.2+. If the browser does not support adding | ||
// properties to `Uint8Array` instances, then that's the same as no `Uint8Array` support | ||
// because we need to be able to add all the node Buffer API methods. This is an issue | ||
// in Firefox 4-29. Now fixed: https://bugzilla.mozilla.org/show_bug.cgi?id=695438 | ||
var TYPED_ARRAY_SUPPORT = (function () { | ||
try { | ||
@@ -32,4 +44,5 @@ var buf = new ArrayBuffer(0) | ||
arr.foo = function () { return 42 } | ||
return 42 === arr.foo() && | ||
typeof arr.subarray === 'function' // Chrome 9-10 lack `subarray` | ||
return 42 === arr.foo() && // typed array instances can be augmented | ||
typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray` | ||
new Uint8Array(1).subarray(1, 1).byteLength === 0 // ie10 has broken `subarray` | ||
} catch (e) { | ||
@@ -67,3 +80,3 @@ return false | ||
} else if (type === 'object' && subject !== null) { // assume object is array-like | ||
if (subject.type === 'Buffer' && Array.isArray(subject.data)) | ||
if (subject.type === 'Buffer' && isArray(subject.data)) | ||
subject = subject.data | ||
@@ -75,3 +88,3 @@ length = +subject.length > 0 ? Math.floor(+subject.length) : 0 | ||
var buf | ||
if (Buffer._useTypedArrays) { | ||
if (TYPED_ARRAY_SUPPORT) { | ||
// Preferred: Return an augmented `Uint8Array` instance for best performance | ||
@@ -87,3 +100,3 @@ buf = Buffer._augment(new Uint8Array(length)) | ||
var i | ||
if (Buffer._useTypedArrays && typeof subject.byteLength === 'number') { | ||
if (TYPED_ARRAY_SUPPORT && typeof subject.byteLength === 'number') { | ||
// Speed optimization -- use set if we're copying from a typed array | ||
@@ -102,3 +115,3 @@ buf._set(subject) | ||
buf.write(subject, 0, encoding) | ||
} else if (type === 'number' && !Buffer._useTypedArrays && !noZero) { | ||
} else if (type === 'number' && !TYPED_ARRAY_SUPPORT && !noZero) { | ||
for (i = 0; i < length; i++) { | ||
@@ -410,3 +423,3 @@ buf[i] = 0 | ||
if (len < 100 || !Buffer._useTypedArrays) { | ||
if (len < 100 || !TYPED_ARRAY_SUPPORT) { | ||
for (var i = 0; i < len; i++) { | ||
@@ -505,3 +518,3 @@ target[i + target_start] = this[i + start] | ||
if (Buffer._useTypedArrays) { | ||
if (TYPED_ARRAY_SUPPORT) { | ||
return Buffer._augment(this.subarray(start, end)) | ||
@@ -965,3 +978,3 @@ } else { | ||
if (typeof Uint8Array !== 'undefined') { | ||
if (Buffer._useTypedArrays) { | ||
if (TYPED_ARRAY_SUPPORT) { | ||
return (new Buffer(this)).buffer | ||
@@ -968,0 +981,0 @@ } else { |
{ | ||
"name": "buffer", | ||
"description": "Node.js Buffer API, for the browser", | ||
"version": "2.4.0", | ||
"version": "2.5.0", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Feross Aboukhadijeh", |
@@ -165,2 +165,7 @@ var B = require('../').Buffer | ||
test('new buffer from buffer.toJSON() output', function (t) { | ||
if (typeof JSON === 'undefined') { | ||
// ie6, ie7 lack support | ||
t.end() | ||
return | ||
} | ||
var buf = new B('test') | ||
@@ -167,0 +172,0 @@ var json = JSON.stringify(buf) |
Sorry, the diff of this file is too big to display
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
1275305
19574