From 4add1722fdcbd478d30322b74d871621a32a4e86 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sun, 29 Jul 2018 21:01:21 +0200 Subject: [PATCH] Use Buffer.allocUnsafe instead of deprecated Buffer API Ref: nodejs/node#19079 Ref: https://nodejs.org/api/deprecations.html#deprecations_dep0005_buffer_constructor Ref: https://nodejs.org/api/buffer.html#buffer_class_buffer --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 7f4e6ce..91b2bec 100644 --- a/index.js +++ b/index.js @@ -97,7 +97,7 @@ module.exports.detectFile = function(filepath, opts, cb) { if (opts && opts.sampleSize) { fd = fs.openSync(filepath, 'r'), - sample = new Buffer(opts.sampleSize); + sample = Buffer.allocUnsafe(opts.sampleSize); fs.read(fd, sample, 0, opts.sampleSize, null, function(err) { handler(err, sample); @@ -111,7 +111,7 @@ module.exports.detectFile = function(filepath, opts, cb) { module.exports.detectFileSync = function(filepath, opts) { if (opts && opts.sampleSize) { var fd = fs.openSync(filepath, 'r'), - sample = new Buffer(opts.sampleSize); + sample = Buffer.allocUnsafe(opts.sampleSize); fs.readSync(fd, sample, 0, opts.sampleSize); fs.closeSync(fd);