Skip to content

Commit df719f5

Browse files
committed
Replace deprecated Buffer methods w/ alloc() + from()
These have been available since Node 5.10.0
1 parent 56d1a60 commit df719f5

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

index.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ function getEndOfCentralDirectoryRecord(self, actuallyJustTellMeHowLongItWouldBe
277277
}
278278
}
279279

280-
var eocdrBuffer = new Buffer(END_OF_CENTRAL_DIRECTORY_RECORD_SIZE);
280+
var eocdrBuffer = Buffer.alloc(END_OF_CENTRAL_DIRECTORY_RECORD_SIZE);
281281
// end of central dir signature 4 bytes (0x06054b50)
282282
eocdrBuffer.writeUInt32LE(0x06054b50, 0);
283283
// number of this disk 2 bytes
@@ -301,7 +301,7 @@ function getEndOfCentralDirectoryRecord(self, actuallyJustTellMeHowLongItWouldBe
301301

302302
// ZIP64 format
303303
// ZIP64 End of Central Directory Record
304-
var zip64EocdrBuffer = new Buffer(ZIP64_END_OF_CENTRAL_DIRECTORY_RECORD_SIZE);
304+
var zip64EocdrBuffer = Buffer.alloc(ZIP64_END_OF_CENTRAL_DIRECTORY_RECORD_SIZE);
305305
// zip64 end of central dir signature 4 bytes (0x06064b50)
306306
zip64EocdrBuffer.writeUInt32LE(0x06064b50, 0);
307307
// size of zip64 end of central directory record 8 bytes
@@ -327,7 +327,7 @@ function getEndOfCentralDirectoryRecord(self, actuallyJustTellMeHowLongItWouldBe
327327

328328

329329
// ZIP64 End of Central Directory Locator
330-
var zip64EocdlBuffer = new Buffer(ZIP64_END_OF_CENTRAL_DIRECTORY_LOCATOR_SIZE);
330+
var zip64EocdlBuffer = Buffer.alloc(ZIP64_END_OF_CENTRAL_DIRECTORY_LOCATOR_SIZE);
331331
// zip64 end of central dir locator signature 4 bytes (0x07064b50)
332332
zip64EocdlBuffer.writeUInt32LE(0x07064b50, 0);
333333
// number of the disk with the start of the zip64 end of central directory 4 bytes
@@ -365,7 +365,7 @@ var defaultDirectoryMode = parseInt("040775", 8);
365365

366366
// this class is not part of the public API
367367
function Entry(metadataPath, isDirectory, options) {
368-
this.utf8FileName = new Buffer(metadataPath);
368+
this.utf8FileName = Buffer.from(metadataPath);
369369
if (this.utf8FileName.length > 0xffff) throw new Error("utf8 file name too long. " + utf8FileName.length + " > " + 0xffff);
370370
this.isDirectory = isDirectory;
371371
this.state = Entry.WAITING_FOR_METADATA;
@@ -440,7 +440,7 @@ Entry.prototype.getLocalFileHeader = function() {
440440
uncompressedSize = this.uncompressedSize;
441441
}
442442

443-
var fixedSizeStuff = new Buffer(LOCAL_FILE_HEADER_FIXED_SIZE);
443+
var fixedSizeStuff = Buffer.alloc(LOCAL_FILE_HEADER_FIXED_SIZE);
444444
var generalPurposeBitFlag = FILE_NAME_IS_UTF8;
445445
if (!this.crcAndFileSizeKnown) generalPurposeBitFlag |= UNKNOWN_CRC32_AND_FILE_SIZES;
446446

@@ -479,10 +479,10 @@ var ZIP64_DATA_DESCRIPTOR_SIZE = 24;
479479
Entry.prototype.getDataDescriptor = function() {
480480
if (this.crcAndFileSizeKnown) {
481481
// the Mac Archive Utility requires this not be present unless we set general purpose bit 3
482-
return new Buffer(0);
482+
return Buffer.alloc(0);
483483
}
484484
if (!this.useZip64Format()) {
485-
var buffer = new Buffer(DATA_DESCRIPTOR_SIZE);
485+
var buffer = Buffer.alloc(DATA_DESCRIPTOR_SIZE);
486486
// optional signature (required according to Archive Utility)
487487
buffer.writeUInt32LE(0x08074b50, 0);
488488
// crc-32 4 bytes
@@ -494,7 +494,7 @@ Entry.prototype.getDataDescriptor = function() {
494494
return buffer;
495495
} else {
496496
// ZIP64 format
497-
var buffer = new Buffer(ZIP64_DATA_DESCRIPTOR_SIZE);
497+
var buffer = Buffer.alloc(ZIP64_DATA_DESCRIPTOR_SIZE);
498498
// optional signature (unknown if anyone cares about this)
499499
buffer.writeUInt32LE(0x08074b50, 0);
500500
// crc-32 4 bytes
@@ -509,7 +509,7 @@ Entry.prototype.getDataDescriptor = function() {
509509
var CENTRAL_DIRECTORY_RECORD_FIXED_SIZE = 46;
510510
var ZIP64_EXTENDED_INFORMATION_EXTRA_FIELD_SIZE = 28;
511511
Entry.prototype.getCentralDirectoryRecord = function() {
512-
var fixedSizeStuff = new Buffer(CENTRAL_DIRECTORY_RECORD_FIXED_SIZE);
512+
var fixedSizeStuff = Buffer.alloc(CENTRAL_DIRECTORY_RECORD_FIXED_SIZE);
513513
var generalPurposeBitFlag = FILE_NAME_IS_UTF8;
514514
if (!this.crcAndFileSizeKnown) generalPurposeBitFlag |= UNKNOWN_CRC32_AND_FILE_SIZES;
515515

@@ -525,7 +525,7 @@ Entry.prototype.getCentralDirectoryRecord = function() {
525525
versionNeededToExtract = VERSION_NEEDED_TO_EXTRACT_ZIP64;
526526

527527
// ZIP64 extended information extra field
528-
zeiefBuffer = new Buffer(ZIP64_EXTENDED_INFORMATION_EXTRA_FIELD_SIZE);
528+
zeiefBuffer = Buffer.alloc(ZIP64_EXTENDED_INFORMATION_EXTRA_FIELD_SIZE);
529529
// 0x0001 2 bytes Tag for this "extra" block type
530530
zeiefBuffer.writeUInt16LE(0x0001, 0);
531531
// Size 2 bytes Size of this "extra" block
@@ -540,7 +540,7 @@ Entry.prototype.getCentralDirectoryRecord = function() {
540540
// (omit)
541541
} else {
542542
versionNeededToExtract = VERSION_NEEDED_TO_EXTRACT_UTF8;
543-
zeiefBuffer = new Buffer(0);
543+
zeiefBuffer = Buffer.alloc(0);
544544
}
545545

546546
// central file header signature 4 bytes (0x02014b50)

test/test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ var BufferList = require("bl");
5757
options.forceZip64Format = !!zip64Config[1];
5858
zipfile.addFile(__filename, "fdsa.txt", options);
5959
options.forceZip64Format = !!zip64Config[2];
60-
zipfile.addBuffer(new Buffer("buffer"), "buffer.txt", options);
60+
zipfile.addBuffer(Buffer.from("buffer"), "buffer.txt", options);
6161
options.forceZip64Format = !!zip64Config[3];
6262
options.size = "stream".length;
6363
zipfile.addReadStream(new BufferList().append("stream"), "stream.txt", options);
@@ -76,7 +76,7 @@ var BufferList = require("bl");
7676
var zipfile = new yazl.ZipFile();
7777
// all options parameters are optional
7878
zipfile.addFile(__filename, "a.txt");
79-
zipfile.addBuffer(new Buffer("buffer"), "b.txt");
79+
zipfile.addBuffer(Buffer.from("buffer"), "b.txt");
8080
zipfile.addReadStream(new BufferList().append("stream"), "c.txt");
8181
zipfile.addEmptyDirectory("d/");
8282
zipfile.addEmptyDirectory("e");
@@ -104,7 +104,7 @@ var BufferList = require("bl");
104104
(function() {
105105
var zipfile = new yazl.ZipFile();
106106
// all options parameters are optional
107-
zipfile.addBuffer(new Buffer("hello"), "hello.txt", {compress: false});
107+
zipfile.addBuffer(Buffer.from("hello"), "hello.txt", {compress: false});
108108
zipfile.end(function(finalSize) {
109109
if (finalSize === -1) throw new Error("finalSize should be known");
110110
zipfile.outputStream.pipe(new BufferList(function(err, data) {

0 commit comments

Comments
 (0)