Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Buffer.alloc (close #114) #131

Merged
merged 1 commit into from Nov 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/index.js
Expand Up @@ -55,7 +55,7 @@ function asyncFileToBuffer (filepath, callback) {
return callback(new Error('File size is not greater than 0 —— ' + filepath));
}
var bufferSize = Math.min(size, MaxBufferSize);
var buffer = new Buffer(bufferSize);
var buffer = Buffer.alloc(bufferSize);
// read first buffer block from the file, asynchronously
fs.read(descriptor, buffer, 0, bufferSize, 0, function (err) {
if (err) { return callback(err); }
Expand All @@ -79,7 +79,7 @@ function syncFileToBuffer (filepath) {
var descriptor = fs.openSync(filepath, 'r');
var size = fs.fstatSync(descriptor).size;
var bufferSize = Math.min(size, MaxBufferSize);
var buffer = new Buffer(bufferSize);
var buffer = Buffer.alloc(bufferSize);
fs.readSync(descriptor, buffer, 0, bufferSize, 0);
fs.closeSync(descriptor);
return buffer;
Expand Down
2 changes: 1 addition & 1 deletion lib/types/tiff.js
Expand Up @@ -24,7 +24,7 @@ function readIFD (buffer, filepath, isBigEndian) {
}

// populate the buffer
var endBuffer = new Buffer(bufferSize);
var endBuffer = Buffer.alloc(bufferSize);
var descriptor = fs.openSync(filepath, 'r');
fs.readSync(descriptor, endBuffer, 0, bufferSize, ifdOffset);

Expand Down
2 changes: 1 addition & 1 deletion specs/fs-close.spec.js
Expand Up @@ -8,7 +8,7 @@ var imageSize = require('..');

describe('after done reading from files', function () {
function readFromClosed (descriptor) {
fs.readSync(descriptor, new Buffer(1), 0, 1, 0);
fs.readSync(descriptor, Buffer.alloc(1), 0, 1, 0);
}

describe('should close the file descriptor', function () {
Expand Down
2 changes: 1 addition & 1 deletion specs/others.spec.js
Expand Up @@ -34,7 +34,7 @@ describe('Invalid invocation', function () {
var bufferSize = 2048;
var file = 'specs/images/valid/tiff/little-endian.tiff';

buffer = new Buffer(bufferSize);
buffer = Buffer.alloc(bufferSize);
var filepath = path.resolve(file);
var descriptor = fs.openSync(filepath, 'r');
fs.readSync(descriptor, buffer, 0, bufferSize, 0);
Expand Down
2 changes: 1 addition & 1 deletion specs/valid.spec.js
Expand Up @@ -105,7 +105,7 @@ describe('Valid images', function () {

beforeEach(function (done) {

var buffer = new Buffer(bufferSize);
var buffer = Buffer.alloc(bufferSize);
var filepath = path.resolve(file);
var descriptor = fs.openSync(filepath, 'r');
fs.readSync(descriptor, buffer, 0, bufferSize, 0);
Expand Down