native-buffer-browserify
Advanced tools
Comparing version 1.1.0 to 1.2.0
170
index.js
var TA = require('typedarray') | ||
exports.Buffer = Buffer | ||
exports.SlowBuffer = Buffer | ||
exports.INSPECT_MAX_BYTES = 50 | ||
Buffer.poolSize = 8192 | ||
/** | ||
* Use a shim for browsers that lack Typed Array support (< IE 9, < FF 3.6, | ||
* < Chrome 6, < Safari 5, < Opera 11.5, < iOS 4.1). | ||
*/ | ||
var xDataView = typeof DataView === 'undefined' | ||
@@ -9,8 +19,26 @@ ? TA.DataView : DataView | ||
exports.Buffer = Buffer | ||
exports.SlowBuffer = Buffer | ||
exports.INSPECT_MAX_BYTES = 50 | ||
Buffer.poolSize = 8192 | ||
/** | ||
* Check to see if the browser supports augmenting a `Uint8Array` instance. | ||
*/ | ||
var browserSupport = (function () { | ||
try { | ||
var arr = new xUint8Array(0) | ||
arr.foo = function () { return 42 } | ||
return 42 === arr.foo() | ||
} catch (e) { | ||
return false | ||
} | ||
})() | ||
var browserSupport | ||
/** | ||
* Also use the shim in Firefox 4-17 (even though they have native Uint8Array), | ||
* since they don't support Proxy. Without that, it is not possible to augment | ||
* native Uint8Array instances in Firefox. | ||
*/ | ||
if (xUint8Array !== TA.Uint8Array && !browserSupport) { | ||
xDataView = TA.DataView | ||
xArrayBuffer = TA.ArrayBuffer | ||
xUint8Array = TA.Uint8Array | ||
browserSupport = true | ||
} | ||
@@ -124,3 +152,3 @@ /** | ||
Buffer.concat = function (list, totalLength) { | ||
if (!Array.isArray(list)) { | ||
if (!isArray(list)) { | ||
throw new Error('Usage: Buffer.concat(list, [totalLength])\n' + | ||
@@ -157,4 +185,4 @@ 'list should be an Array.') | ||
// INSTANCE METHODS | ||
// ================ | ||
// BUFFER INSTANCE METHODS | ||
// ======================= | ||
@@ -298,3 +326,3 @@ function _hexWrite (buf, string, offset, length) { | ||
type: 'Buffer', | ||
data: Array.prototype.slice.call(this, 0) | ||
data: Array.prototype.slice.call(this._arr || this, 0) | ||
} | ||
@@ -854,17 +882,2 @@ } | ||
/** | ||
* Check to see if the browser supports augmenting a `Uint8Array` instance. | ||
* @return {boolean} | ||
*/ | ||
function _browserSupport () { | ||
var arr = new xUint8Array(0) | ||
arr.foo = function () { return 42 } | ||
try { | ||
return (42 === arr.foo()) | ||
} catch (e) { | ||
return false | ||
} | ||
} | ||
/** | ||
* Class: ProxyBuffer | ||
@@ -907,46 +920,48 @@ * ================== | ||
ProxyBuffer.prototype.write = BufferWrite | ||
ProxyBuffer.prototype.toString = BufferToString | ||
ProxyBuffer.prototype.toLocaleString = BufferToString | ||
ProxyBuffer.prototype.toJSON = BufferToJSON | ||
ProxyBuffer.prototype.copy = BufferCopy | ||
ProxyBuffer.prototype.slice = BufferSlice | ||
ProxyBuffer.prototype.readUInt8 = BufferReadUInt8 | ||
ProxyBuffer.prototype.readUInt16LE = BufferReadUInt16LE | ||
ProxyBuffer.prototype.readUInt16BE = BufferReadUInt16BE | ||
ProxyBuffer.prototype.readUInt32LE = BufferReadUInt32LE | ||
ProxyBuffer.prototype.readUInt32BE = BufferReadUInt32BE | ||
ProxyBuffer.prototype.readInt8 = BufferReadInt8 | ||
ProxyBuffer.prototype.readInt16LE = BufferReadInt16LE | ||
ProxyBuffer.prototype.readInt16BE = BufferReadInt16BE | ||
ProxyBuffer.prototype.readInt32LE = BufferReadInt32LE | ||
ProxyBuffer.prototype.readInt32BE = BufferReadInt32BE | ||
ProxyBuffer.prototype.readFloatLE = BufferReadFloatLE | ||
ProxyBuffer.prototype.readFloatBE = BufferReadFloatBE | ||
ProxyBuffer.prototype.readDoubleLE = BufferReadDoubleLE | ||
ProxyBuffer.prototype.readDoubleBE = BufferReadDoubleBE | ||
ProxyBuffer.prototype.writeUInt8 = BufferWriteUInt8 | ||
ProxyBuffer.prototype.writeUInt16LE = BufferWriteUInt16LE | ||
ProxyBuffer.prototype.writeUInt16BE = BufferWriteUInt16BE | ||
ProxyBuffer.prototype.writeUInt32LE = BufferWriteUInt32LE | ||
ProxyBuffer.prototype.writeUInt32BE = BufferWriteUInt32BE | ||
ProxyBuffer.prototype.writeInt8 = BufferWriteInt8 | ||
ProxyBuffer.prototype.writeInt16LE = BufferWriteInt16LE | ||
ProxyBuffer.prototype.writeInt16BE = BufferWriteInt16BE | ||
ProxyBuffer.prototype.writeInt32LE = BufferWriteInt32LE | ||
ProxyBuffer.prototype.writeInt32BE = BufferWriteInt32BE | ||
ProxyBuffer.prototype.writeFloatLE = BufferWriteFloatLE | ||
ProxyBuffer.prototype.writeFloatBE = BufferWriteFloatBE | ||
ProxyBuffer.prototype.writeDoubleLE = BufferWriteDoubleLE | ||
ProxyBuffer.prototype.writeDoubleBE = BufferWriteDoubleBE | ||
ProxyBuffer.prototype.fill = BufferFill | ||
ProxyBuffer.prototype.inspect = BufferInspect | ||
ProxyBuffer.prototype.toArrayBuffer = BufferToArrayBuffer | ||
ProxyBuffer.prototype._isBuffer = true | ||
ProxyBuffer.prototype.subarray = function () { | ||
return this._arr.subarray.apply(this._arr, arguments) | ||
ProxyBuffer.prototype = { | ||
_isBuffer: true, | ||
write: BufferWrite, | ||
toString: BufferToString, | ||
toLocaleString: BufferToString, | ||
toJSON: BufferToJSON, | ||
copy: BufferCopy, | ||
slice: BufferSlice, | ||
readUInt8: BufferReadUInt8, | ||
readUInt16LE: BufferReadUInt16LE, | ||
readUInt16BE: BufferReadUInt16BE, | ||
readUInt32LE: BufferReadUInt32LE, | ||
readUInt32BE: BufferReadUInt32BE, | ||
readInt8: BufferReadInt8, | ||
readInt16LE: BufferReadInt16LE, | ||
readInt16BE: BufferReadInt16BE, | ||
readInt32LE: BufferReadInt32LE, | ||
readInt32BE: BufferReadInt32BE, | ||
readFloatLE: BufferReadFloatLE, | ||
readFloatBE: BufferReadFloatBE, | ||
readDoubleLE: BufferReadDoubleLE, | ||
readDoubleBE: BufferReadDoubleBE, | ||
writeUInt8: BufferWriteUInt8, | ||
writeUInt16LE: BufferWriteUInt16LE, | ||
writeUInt16BE: BufferWriteUInt16BE, | ||
writeUInt32LE: BufferWriteUInt32LE, | ||
writeUInt32BE: BufferWriteUInt32BE, | ||
writeInt8: BufferWriteInt8, | ||
writeInt16LE: BufferWriteInt16LE, | ||
writeInt16BE: BufferWriteInt16BE, | ||
writeInt32LE: BufferWriteInt32LE, | ||
writeInt32BE: BufferWriteInt32BE, | ||
writeFloatLE: BufferWriteFloatLE, | ||
writeFloatBE: BufferWriteFloatBE, | ||
writeDoubleLE: BufferWriteDoubleLE, | ||
writeDoubleBE: BufferWriteDoubleBE, | ||
fill: BufferFill, | ||
inspect: BufferInspect, | ||
toArrayBuffer: BufferToArrayBuffer, | ||
subarray: function () { | ||
return this._arr.subarray.apply(this._arr, arguments) | ||
}, | ||
set: function () { | ||
return this._arr.set.apply(this._arr, arguments) | ||
} | ||
} | ||
ProxyBuffer.prototype.set = function () { | ||
return this._arr.set.apply(this._arr, arguments) | ||
} | ||
@@ -964,7 +979,5 @@ var ProxyHandler = { | ||
function augment (arr) { | ||
if (browserSupport === undefined) { | ||
browserSupport = _browserSupport() | ||
} | ||
if (browserSupport) { | ||
arr._isBuffer = true | ||
if (browserSupport) { | ||
// Augment the Uint8Array *instance* (not the class!) with Buffer methods | ||
@@ -1007,5 +1020,8 @@ arr.write = BufferWrite | ||
arr.inspect = BufferInspect | ||
arr.toArrayBuffer = BufferToArrayBuffer | ||
arr._isBuffer = true | ||
// Only add `toArrayBuffer` if we're using an augmented native Uint8Array | ||
if (xUint8Array !== TA.Uint8Array) { | ||
arr.toArrayBuffer = BufferToArrayBuffer | ||
} | ||
if (arr.byteLength !== 0) | ||
@@ -1045,4 +1061,10 @@ arr._dataview = new xDataView(arr.buffer, arr.byteOffset, arr.byteLength) | ||
function isArray (subject) { | ||
return (Array.isArray || function (subject) { | ||
return Object.prototype.toString.call(subject) === '[object Array]' | ||
})(subject) | ||
} | ||
function isArrayIsh (subject) { | ||
return Array.isArray(subject) || Buffer.isBuffer(subject) || | ||
return isArray(subject) || Buffer.isBuffer(subject) || | ||
subject && typeof subject === 'object' && | ||
@@ -1049,0 +1071,0 @@ typeof subject.length === 'number' |
{ | ||
"name": "native-buffer-browserify", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "buffer module compatibility for browserify (backed by ArrayBuffer so its fast!)", | ||
"main": "index.js", | ||
"dependencies": { | ||
"base64-js": "0.0.4", | ||
"typedarray": "~0.0.0" | ||
"base64-js": "~0.0.4", | ||
"typedarray": "~0.0.4" | ||
}, | ||
"devDependencies": { | ||
"tape": "~2.1.0", | ||
"benchmark": "~1.0.0", | ||
"browserify": "~2.35.4" | ||
"benchmark": "1.x", | ||
"browserify": "*", | ||
"tape": "2.x" | ||
}, | ||
@@ -23,8 +23,9 @@ "repository": { | ||
"ie/6..latest", | ||
"chrome/20..latest", | ||
"firefox/10..latest", | ||
"safari/latest", | ||
"chrome/4..latest", | ||
"firefox/3..latest", | ||
"safari/5.1..latest", | ||
"opera/11.0..latest", | ||
"iphone/6", | ||
"ipad/6" | ||
"ipad/6", | ||
"android-browser/4.2" | ||
] | ||
@@ -36,3 +37,2 @@ }, | ||
"compatible", | ||
"meatless", | ||
"browser", | ||
@@ -45,11 +45,10 @@ "arraybuffer", | ||
"contributors": [ | ||
"Romain Beauxis <toots@rastageeks.org>" | ||
"Romain Beauxis <toots@rastageeks.org>", | ||
"James Halliday <mail@substack.net>" | ||
], | ||
"scripts": { | ||
"test": "tape test/*.js" | ||
"test": "tape test/*.js", | ||
"perf": "browserify --debug perf/concat.js > perf/bundle.js && open perf/index.html" | ||
}, | ||
"license": "MIT", | ||
"engine": { | ||
"node": ">=0.6" | ||
} | ||
"license": "MIT" | ||
} |
native-buffer-browserify | ||
=============== | ||
The buffer module from [node.js](http://nodejs.org/), but for browsers. This is a fork of [buffer-browserify](https://github.com/toots/buffer-browserify). | ||
The buffer module from [node.js](http://nodejs.org/), but for browsers. This is | ||
a fork of [buffer-browserify](https://github.com/toots/buffer-browserify). | ||
[![build status](https://secure.travis-ci.org/feross/native-buffer-browserify.png)](http://travis-ci.org/feross/native-buffer-browserify) | ||
[![testling badge](https://ci.testling.com/feross/native-buffer-browserify.png)](https://ci.testling.com/feross/native-buffer-browserify) | ||
When you `require('buffer')` in | ||
[browserify](http://github.com/substack/node-browserify), | ||
this module will be loaded. | ||
[browserify](http://github.com/substack/node-browserify), this module will be | ||
loaded. | ||
@@ -21,5 +26,5 @@ It will also be loaded if you use the global `Buffer` variable. | ||
- All tests from the original `buffer-browserify` project pass. | ||
- Requires browsers to have `Uint8Array` and `DataView` support (all modern browsers, IE10+) | ||
- Requires browsers to have `Uint8Array` and `DataView` support (all modern | ||
browsers, IE10+, shim for older browsers included) | ||
## How does it work? | ||
@@ -26,0 +31,0 @@ |
var B = require('../index.js').Buffer | ||
var test = require('tape') | ||
var TA = require('typedarray') | ||
var xUint16Array = typeof Uint16Array === 'undefined' | ||
? TA.Uint16Array : Uint16Array | ||
var xUint8Array = typeof Uint8Array === 'undefined' | ||
? TA.Uint8Array : Uint8Array | ||
@@ -28,13 +23,16 @@ test('new buffer from array', function (t) { | ||
function arraybufferToString (arraybuffer) { | ||
return String.fromCharCode.apply(null, new xUint16Array(arraybuffer)) | ||
return String.fromCharCode.apply(null, new Uint16Array(arraybuffer)) | ||
} | ||
test('buffer toArrayBuffer()', function (t) { | ||
t.plan(1) | ||
var data = [1, 2, 3, 4, 5, 6, 7, 8] | ||
var data = [1, 2, 3, 4, 5, 6, 7, 8] | ||
if (typeof (new B(data)).toArrayBuffer === 'function') { | ||
t.equal( | ||
arraybufferToString(new B(data).toArrayBuffer()), | ||
arraybufferToString(new xUint8Array(data).buffer) | ||
arraybufferToString(new Uint8Array(data).buffer) | ||
) | ||
t.end() | ||
} else { | ||
t.pass('No toArrayBuffer() method provided in old browsers') | ||
} | ||
t.end() | ||
}) | ||
@@ -41,0 +39,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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances 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
256289
7414
133
4
2
+ Addedbase64-js@0.0.8(transitive)
- Removedbase64-js@0.0.4(transitive)
Updatedbase64-js@~0.0.4
Updatedtypedarray@~0.0.4