From 4947abe88bc49eeaecb85ec12f0f3069bf2c287d Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Thu, 7 May 2020 10:42:05 +0100 Subject: [PATCH] fix deprecated usage of Buffer constructor --- services/clsi/app/js/OutputFileOptimiser.js | 3 +-- services/clsi/app/js/SafeReader.js | 2 +- services/clsi/test/unit/js/OutputFileOptimiserTests.js | 6 +++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/services/clsi/app/js/OutputFileOptimiser.js b/services/clsi/app/js/OutputFileOptimiser.js index c0b8cc141a..1af2045295 100644 --- a/services/clsi/app/js/OutputFileOptimiser.js +++ b/services/clsi/app/js/OutputFileOptimiser.js @@ -45,8 +45,7 @@ module.exports = OutputFileOptimiser = { checkIfPDFIsOptimised(file, callback) { const SIZE = 16 * 1024 // check the header of the pdf - const result = new Buffer(SIZE) - result.fill(0) // prevent leakage of uninitialised buffer + const result = Buffer.alloc(SIZE) // fills with zeroes by default return fs.open(file, 'r', function(err, fd) { if (err != null) { return callback(err) diff --git a/services/clsi/app/js/SafeReader.js b/services/clsi/app/js/SafeReader.js index d909e37e73..900826756a 100644 --- a/services/clsi/app/js/SafeReader.js +++ b/services/clsi/app/js/SafeReader.js @@ -43,7 +43,7 @@ module.exports = SafeReader = { } return callback(null, ...Array.from(result)) }) - const buff = new Buffer(size, 0) // fill with zeros + const buff = Buffer.alloc(size) // fills with zeroes by default return fs.read(fd, buff, 0, buff.length, 0, function( err, bytesRead, diff --git a/services/clsi/test/unit/js/OutputFileOptimiserTests.js b/services/clsi/test/unit/js/OutputFileOptimiserTests.js index 4546f08431..b4983bf0f8 100644 --- a/services/clsi/test/unit/js/OutputFileOptimiserTests.js +++ b/services/clsi/test/unit/js/OutputFileOptimiserTests.js @@ -124,7 +124,7 @@ describe('OutputFileOptimiser', function() { this.fs.read = sinon .stub() .withArgs(this.fd) - .yields(null, 100, new Buffer('hello /Linearized 1')) + .yields(null, 100, Buffer.from('hello /Linearized 1')) this.fs.close = sinon .stub() .withArgs(this.fd) @@ -140,7 +140,7 @@ describe('OutputFileOptimiser', function() { this.fs.read = sinon .stub() .withArgs(this.fd) - .yields(null, 100, new Buffer('hello /Linearized 1')) + .yields(null, 100, Buffer.from('hello /Linearized 1')) return this.OutputFileOptimiser.checkIfPDFIsOptimised( this.src, this.callback @@ -169,7 +169,7 @@ describe('OutputFileOptimiser', function() { this.fs.read = sinon .stub() .withArgs(this.fd) - .yields(null, 100, new Buffer('hello not linearized 1')) + .yields(null, 100, Buffer.from('hello not linearized 1')) return this.OutputFileOptimiser.checkIfPDFIsOptimised( this.src, this.callback