Skip to content

Commit

Permalink
re kawanet#98: Buffer.from() and Buffer.alloc()
Browse files Browse the repository at this point in the history
node v4.5+ required
  • Loading branch information
kawanet committed Oct 17, 2018
1 parent 3b66536 commit 641d3e6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
19 changes: 3 additions & 16 deletions lib/bufferish-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,12 @@
var Bufferish = require("./bufferish");
var Buffer = Bufferish.global;

var exports = module.exports = Bufferish.hasBuffer ? alloc(0) : [];
var exports = module.exports = Buffer ? Buffer.alloc(0) : [];

exports.alloc = Bufferish.hasBuffer && Buffer.alloc || alloc;
exports.alloc = Buffer && Buffer.alloc;
exports.concat = Bufferish.concat;
exports.from = from;

/**
* @param size {Number}
* @returns {Buffer|Uint8Array|Array}
*/

function alloc(size) {
return new Buffer(size);
}

/**
* @param value {Array|ArrayBuffer|Buffer|String}
* @returns {Buffer}
Expand All @@ -38,9 +29,5 @@ function from(value) {
}

// Array-like to Buffer
if (Buffer.from && Buffer.from.length !== 1) {
return Buffer.from(value); // node v6+
} else {
return new Buffer(value); // node v4
}
return Buffer.from(value); // node v4.5+
}
2 changes: 1 addition & 1 deletion lib/ext-unpacker.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function setExtUnpackers(codec) {
}

if (Bufferish.hasBuffer) {
codec.addExtUnpacker(0x1B, unpackClass(Buffer));
codec.addExtUnpacker(0x1B, Buffer.from);
}
}

Expand Down

0 comments on commit 641d3e6

Please sign in to comment.