Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for node 4.2.0 to 4.4.7 with specific buffer polyfill #665

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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