Merge pull request #164 from overleaf/bg-fix-buffer-deprecations
fix deprecated usage of Buffer constructor
This commit is contained in:
@@ -45,8 +45,7 @@ module.exports = OutputFileOptimiser = {
|
|||||||
|
|
||||||
checkIfPDFIsOptimised(file, callback) {
|
checkIfPDFIsOptimised(file, callback) {
|
||||||
const SIZE = 16 * 1024 // check the header of the pdf
|
const SIZE = 16 * 1024 // check the header of the pdf
|
||||||
const result = new Buffer(SIZE)
|
const result = Buffer.alloc(SIZE) // fills with zeroes by default
|
||||||
result.fill(0) // prevent leakage of uninitialised buffer
|
|
||||||
return fs.open(file, 'r', function(err, fd) {
|
return fs.open(file, 'r', function(err, fd) {
|
||||||
if (err != null) {
|
if (err != null) {
|
||||||
return callback(err)
|
return callback(err)
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ module.exports = SafeReader = {
|
|||||||
}
|
}
|
||||||
return callback(null, ...Array.from(result))
|
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(
|
return fs.read(fd, buff, 0, buff.length, 0, function(
|
||||||
err,
|
err,
|
||||||
bytesRead,
|
bytesRead,
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ describe('OutputFileOptimiser', function() {
|
|||||||
this.fs.read = sinon
|
this.fs.read = sinon
|
||||||
.stub()
|
.stub()
|
||||||
.withArgs(this.fd)
|
.withArgs(this.fd)
|
||||||
.yields(null, 100, new Buffer('hello /Linearized 1'))
|
.yields(null, 100, Buffer.from('hello /Linearized 1'))
|
||||||
this.fs.close = sinon
|
this.fs.close = sinon
|
||||||
.stub()
|
.stub()
|
||||||
.withArgs(this.fd)
|
.withArgs(this.fd)
|
||||||
@@ -140,7 +140,7 @@ describe('OutputFileOptimiser', function() {
|
|||||||
this.fs.read = sinon
|
this.fs.read = sinon
|
||||||
.stub()
|
.stub()
|
||||||
.withArgs(this.fd)
|
.withArgs(this.fd)
|
||||||
.yields(null, 100, new Buffer('hello /Linearized 1'))
|
.yields(null, 100, Buffer.from('hello /Linearized 1'))
|
||||||
return this.OutputFileOptimiser.checkIfPDFIsOptimised(
|
return this.OutputFileOptimiser.checkIfPDFIsOptimised(
|
||||||
this.src,
|
this.src,
|
||||||
this.callback
|
this.callback
|
||||||
@@ -169,7 +169,7 @@ describe('OutputFileOptimiser', function() {
|
|||||||
this.fs.read = sinon
|
this.fs.read = sinon
|
||||||
.stub()
|
.stub()
|
||||||
.withArgs(this.fd)
|
.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(
|
return this.OutputFileOptimiser.checkIfPDFIsOptimised(
|
||||||
this.src,
|
this.src,
|
||||||
this.callback
|
this.callback
|
||||||
|
|||||||
Reference in New Issue
Block a user