Buffer.alloc to init Buffer with a length

This commit is contained in:
David Stephens 2018-04-28 14:06:36 +01:00
parent f16eb6f3e6
commit 0d7676a871

View file

@ -82,7 +82,7 @@ module.exports = class ArchiveUtil {
fileType.offset = fileType.offset || 0; fileType.offset = fileType.offset || 0;
// :TODO: this is broken: sig is NOT this long, it's sig.length long; offset needs to allow for -negative values as well // :TODO: this is broken: sig is NOT this long, it's sig.length long; offset needs to allow for -negative values as well
const sigLen =fileType.offset + fileType.sig.length; const sigLen = fileType.offset + fileType.sig.length;
if(sigLen > this.longestSignature) { if(sigLen > this.longestSignature) {
this.longestSignature = sigLen; this.longestSignature = sigLen;
} }
@ -120,7 +120,7 @@ module.exports = class ArchiveUtil {
return cb(err); return cb(err);
} }
const buf = Buffer.from(this.longestSignature); const buf = Buffer.alloc(this.longestSignature);
fs.read(fd, buf, 0, buf.length, 0, (err, bytesRead) => { fs.read(fd, buf, 0, buf.length, 0, (err, bytesRead) => {
if(err) { if(err) {
return cb(err); return cb(err);