Closed ghost closed 7 years ago
Seems like there is an issue with NodejS 4.x and ArrayBuffer, so maybe you should check whether Buffer constructor accepts ArrayBuffer or not?
Something like this?
var toBuffer = (function () { // check whether Buffer constructor accepts ArrayBuffer or not function isBufferConstructorAcceptsArrayBuffer() { try { return typeof Uint8Array === 'function' && (new Buffer(new Uint8Array([1]).buffer)[0] === 1); } catch (e) { return false; } } if (isBufferConstructorAcceptsArrayBuffer()) { // Node 4.x return function (ab) { return new Buffer(ab); }; } else { // Node 0.10.x and 0.12.x return function (ab) { var buffer = new Buffer(ab.byteLength); var view = new Uint8Array(ab); for (var i = 0; i < buffer.length; ++i) { buffer[i] = view[i]; } return buffer; }; } })();
My algorithm has no dependency on this fact at all. I just read it like any other indexed number-only collection.
Seems like there is an issue with NodejS 4.x and ArrayBuffer, so maybe you should check whether Buffer constructor accepts ArrayBuffer or not?
Something like this?