native-buffer-browserify
Advanced tools
Comparing version 1.0.3 to 1.1.0
38
index.js
@@ -0,1 +1,9 @@ | ||
var TA = require('typedarray') | ||
var xDataView = typeof DataView === 'undefined' | ||
? TA.DataView : DataView | ||
var xArrayBuffer = typeof ArrayBuffer === 'undefined' | ||
? TA.ArrayBuffer : ArrayBuffer | ||
var xUint8Array = typeof Uint8Array === 'undefined' | ||
? TA.Uint8Array : Uint8Array | ||
exports.Buffer = Buffer | ||
@@ -47,3 +55,3 @@ exports.SlowBuffer = Buffer | ||
var buf = augment(new Uint8Array(length)) | ||
var buf = augment(new xUint8Array(length)) | ||
if (Buffer.isBuffer(subject)) { | ||
@@ -409,3 +417,3 @@ // Speed optimization -- use set if we're copying from a Uint8Array | ||
} else if (offset + 1 === len) { | ||
var dv = new DataView(new ArrayBuffer(2)) | ||
var dv = new xDataView(new xArrayBuffer(2)) | ||
dv.setUint8(0, buf[len - 1]) | ||
@@ -438,3 +446,3 @@ return dv.getUint16(0, littleEndian) | ||
} else if (offset + 3 >= len) { | ||
var dv = new DataView(new ArrayBuffer(4)) | ||
var dv = new xDataView(new xArrayBuffer(4)) | ||
for (var i = 0; i + offset < len; i++) { | ||
@@ -484,3 +492,3 @@ dv.setUint8(i, buf[i + offset]) | ||
} else if (offset + 1 === len) { | ||
var dv = new DataView(new ArrayBuffer(2)) | ||
var dv = new xDataView(new xArrayBuffer(2)) | ||
dv.setUint8(0, buf[len - 1]) | ||
@@ -513,3 +521,3 @@ return dv.getInt16(0, littleEndian) | ||
} else if (offset + 3 >= len) { | ||
var dv = new DataView(new ArrayBuffer(4)) | ||
var dv = new xDataView(new xArrayBuffer(4)) | ||
for (var i = 0; i + offset < len; i++) { | ||
@@ -596,3 +604,3 @@ dv.setUint8(i, buf[i + offset]) | ||
} else if (offset + 1 === len) { | ||
var dv = new DataView(new ArrayBuffer(2)) | ||
var dv = new xDataView(new xArrayBuffer(2)) | ||
dv.setUint16(0, value, littleEndian) | ||
@@ -627,3 +635,3 @@ buf[offset] = dv.getUint8(0) | ||
} else if (offset + 3 >= len) { | ||
var dv = new DataView(new ArrayBuffer(4)) | ||
var dv = new xDataView(new xArrayBuffer(4)) | ||
dv.setUint32(0, value, littleEndian) | ||
@@ -674,3 +682,3 @@ for (var i = 0; i + offset < len; i++) { | ||
} else if (offset + 1 === len) { | ||
var dv = new DataView(new ArrayBuffer(2)) | ||
var dv = new xDataView(new xArrayBuffer(2)) | ||
dv.setInt16(0, value, littleEndian) | ||
@@ -705,3 +713,3 @@ buf[offset] = dv.getUint8(0) | ||
} else if (offset + 3 >= len) { | ||
var dv = new DataView(new ArrayBuffer(4)) | ||
var dv = new xDataView(new xArrayBuffer(4)) | ||
dv.setInt32(0, value, littleEndian) | ||
@@ -738,3 +746,3 @@ for (var i = 0; i + offset < len; i++) { | ||
} else if (offset + 3 >= len) { | ||
var dv = new DataView(new ArrayBuffer(4)) | ||
var dv = new xDataView(new xArrayBuffer(4)) | ||
dv.setFloat32(0, value, littleEndian) | ||
@@ -772,3 +780,3 @@ for (var i = 0; i + offset < len; i++) { | ||
} else if (offset + 7 >= len) { | ||
var dv = new DataView(new ArrayBuffer(8)) | ||
var dv = new xDataView(new xArrayBuffer(8)) | ||
dv.setFloat64(0, value, littleEndian) | ||
@@ -857,3 +865,3 @@ for (var i = 0; i + offset < len; i++) { | ||
function _browserSupport () { | ||
var arr = new Uint8Array(0) | ||
var arr = new xUint8Array(0) | ||
arr.foo = function () { return 42 } | ||
@@ -903,3 +911,3 @@ | ||
if (arr.byteLength !== 0) | ||
this._dataview = new DataView(arr.buffer, arr.byteOffset, arr.byteLength) | ||
this._dataview = new xDataView(arr.buffer, arr.byteOffset, arr.byteLength) | ||
} | ||
@@ -1009,3 +1017,3 @@ | ||
if (arr.byteLength !== 0) | ||
arr._dataview = new DataView(arr.buffer, arr.byteOffset, arr.byteLength) | ||
arr._dataview = new xDataView(arr.buffer, arr.byteOffset, arr.byteLength) | ||
@@ -1137,2 +1145,2 @@ return arr | ||
if (!test) throw new Error(message || 'Failed assertion') | ||
} | ||
} |
{ | ||
"name": "native-buffer-browserify", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"description": "buffer module compatibility for browserify (backed by ArrayBuffer so its fast!)", | ||
"main": "index.js", | ||
"dependencies": { | ||
"base64-js": "0.0.4" | ||
"base64-js": "0.0.4", | ||
"typedarray": "~0.0.0" | ||
}, | ||
@@ -9,0 +10,0 @@ "devDependencies": { |
@@ -125,4 +125,4 @@ native-buffer-browserify | ||
## License | ||
## MIT License | ||
MIT | ||
Copyright (C) 2013 [Feross Aboukhadijeh](http://feross.org), Romain Beauxis, and other contributors. |
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 | ||
@@ -8,3 +13,3 @@ test('new buffer from array', function (t) { | ||
new B([1, 2, 3]).toString(), | ||
new Buffer([1, 2, 3]).toString() | ||
'\u0001\u0002\u0003' | ||
) | ||
@@ -18,3 +23,3 @@ t.end() | ||
new B('hey', 'utf8').toString(), | ||
new Buffer('hey', 'utf8').toString() | ||
'hey' | ||
) | ||
@@ -25,3 +30,3 @@ t.end() | ||
function arraybufferToString (arraybuffer) { | ||
return String.fromCharCode.apply(null, new Uint16Array(arraybuffer)) | ||
return String.fromCharCode.apply(null, new xUint16Array(arraybuffer)) | ||
} | ||
@@ -34,3 +39,3 @@ | ||
arraybufferToString(new B(data).toArrayBuffer()), | ||
arraybufferToString(new Uint8Array(data).buffer) | ||
arraybufferToString(new xUint8Array(data).buffer) | ||
) | ||
@@ -37,0 +42,0 @@ t.end() |
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
57856
21
1594
128
2
+ Addedtypedarray@~0.0.0
+ Addedtypedarray@0.0.7(transitive)