Skip to content

Commit

Permalink
check for Buffer.allocUnsafe once
Browse files Browse the repository at this point in the history
  • Loading branch information
thejoshwolfe committed Apr 25, 2018
1 parent 87da12f commit 9820dad
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions index.js
Expand Up @@ -770,9 +770,16 @@ function readUInt64LE(buffer, offset) {
// we'll catch any overflow errors, because we already made sure the total file size was within reason.
}

function newBuffer(len) {
if (typeof Buffer.allocUnsafe === "function") return Buffer.allocUnsafe(len);
return new Buffer(len);
// Node 10 deprecated new Buffer().
var newBuffer;
if (typeof Buffer.allocUnsafe === "function") {
newBuffer = function(len) {
return Buffer.allocUnsafe(len);
};
} else {
newBuffer = function(len) {
return new Buffer(len);
};
}

function defaultCallback(err) {
Expand Down

0 comments on commit 9820dad

Please sign in to comment.