Skip to content

Commit 1afe674

Browse files
author
Nick DeLuca
committed
add support for node 4.2.0 to 4.4.7 by adding a specific buffer polyfill
1 parent 942011d commit 1afe674

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/util/minimal.js

+18
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,24 @@ util.Buffer = (function() {
7070
if (!Buffer.prototype.utf8Write) // refuse to use non-node buffers (performance)
7171
return null;
7272

73+
// Node 4.2.0 to 4.4.7 Support. Unfortunatly not 4.0.0 - 4.1.2 compatible
74+
// See - https://github.com/nodejs/node/pull/3080 for reference
75+
if (Buffer.from && Buffer.from.toString() === Uint8Array.from.toString()) {
76+
function PolyBuffer(arg, encoding) {
77+
var b = new Buffer(arg, encoding);
78+
Object.setPrototypeOf(b, PolyBuffer.prototype);
79+
return b;
80+
}
81+
82+
PolyBuffer.from = function(value, encoding) { return new PolyBuffer(value, encoding); };
83+
PolyBuffer.allocUnsafe = function allocUnsafe(size) { return new PolyBuffer(size); };
84+
85+
Object.setPrototypeOf(PolyBuffer.prototype, Buffer.prototype);
86+
Object.setPrototypeOf(PolyBuffer, Buffer);
87+
88+
return PolyBuffer;
89+
}
90+
7391
/* istanbul ignore next */
7492
if (!Buffer.from)
7593
Buffer.from = function from(value, encoding) { return new Buffer(value, encoding); };

0 commit comments

Comments
 (0)