Skip to content

Commit

Permalink
add support for node 4.2.0 to 4.4.7 by adding a specific buffer polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick DeLuca committed Jan 28, 2017
1 parent 942011d commit 1afe674
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/util/minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,24 @@ util.Buffer = (function() {
if (!Buffer.prototype.utf8Write) // refuse to use non-node buffers (performance)
return null;

// Node 4.2.0 to 4.4.7 Support. Unfortunatly not 4.0.0 - 4.1.2 compatible
// See - https://github.com/nodejs/node/pull/3080 for reference
if (Buffer.from && Buffer.from.toString() === Uint8Array.from.toString()) {
function PolyBuffer(arg, encoding) {
var b = new Buffer(arg, encoding);
Object.setPrototypeOf(b, PolyBuffer.prototype);
return b;
}

PolyBuffer.from = function(value, encoding) { return new PolyBuffer(value, encoding); };
PolyBuffer.allocUnsafe = function allocUnsafe(size) { return new PolyBuffer(size); };

Object.setPrototypeOf(PolyBuffer.prototype, Buffer.prototype);
Object.setPrototypeOf(PolyBuffer, Buffer);

return PolyBuffer;
}

/* istanbul ignore next */
if (!Buffer.from)
Buffer.from = function from(value, encoding) { return new Buffer(value, encoding); };
Expand Down

0 comments on commit 1afe674

Please sign in to comment.