Skip to content

Commit a6eb2c8

Browse files
authored
Merge pull request #43 from mojodna/buffer-deprecation
Replace deprecated Buffer methods w/ alloc() + from()
2 parents 8da7f4a + df719f5 commit a6eb2c8

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
@@ -362,7 +362,7 @@ function validateMetadataPath(metadataPath, isDirectory) {
362362

363363
// this class is not part of the public API
364364
function Entry(metadataPath, isDirectory, options) {
365-
this.utf8FileName = new Buffer(metadataPath);
365+
this.utf8FileName = Buffer.from(metadataPath);
366366
if (this.utf8FileName.length > 0xffff) throw new Error("utf8 file name too long. " + utf8FileName.length + " > " + 0xffff);
367367
this.isDirectory = isDirectory;
368368
this.state = Entry.WAITING_FOR_METADATA;
@@ -437,7 +437,7 @@ Entry.prototype.getLocalFileHeader = function() {
437437
uncompressedSize = this.uncompressedSize;
438438
}
439439

440-
var fixedSizeStuff = new Buffer(LOCAL_FILE_HEADER_FIXED_SIZE);
440+
var fixedSizeStuff = Buffer.alloc(LOCAL_FILE_HEADER_FIXED_SIZE);
441441
var generalPurposeBitFlag = FILE_NAME_IS_UTF8;
442442
if (!this.crcAndFileSizeKnown) generalPurposeBitFlag |= UNKNOWN_CRC32_AND_FILE_SIZES;
443443

@@ -476,10 +476,10 @@ var ZIP64_DATA_DESCRIPTOR_SIZE = 24;
476476
Entry.prototype.getDataDescriptor = function() {
477477
if (this.crcAndFileSizeKnown) {
478478
// the Mac Archive Utility requires this not be present unless we set general purpose bit 3
479-
return new Buffer(0);
479+
return Buffer.alloc(0);
480480
}
481481
if (!this.useZip64Format()) {
482-
var buffer = new Buffer(DATA_DESCRIPTOR_SIZE);
482+
var buffer = Buffer.alloc(DATA_DESCRIPTOR_SIZE);
483483
// optional signature (required according to Archive Utility)
484484
buffer.writeUInt32LE(0x08074b50, 0);
485485
// crc-32 4 bytes
@@ -491,7 +491,7 @@ Entry.prototype.getDataDescriptor = function() {
491491
return buffer;
492492
} else {
493493
// ZIP64 format
494-
var buffer = new Buffer(ZIP64_DATA_DESCRIPTOR_SIZE);
494+
var buffer = Buffer.alloc(ZIP64_DATA_DESCRIPTOR_SIZE);
495495
// optional signature (unknown if anyone cares about this)
496496
buffer.writeUInt32LE(0x08074b50, 0);
497497
// crc-32 4 bytes
@@ -506,7 +506,7 @@ Entry.prototype.getDataDescriptor = function() {
506506
var CENTRAL_DIRECTORY_RECORD_FIXED_SIZE = 46;
507507
var ZIP64_EXTENDED_INFORMATION_EXTRA_FIELD_SIZE = 28;
508508
Entry.prototype.getCentralDirectoryRecord = function() {
509-
var fixedSizeStuff = new Buffer(CENTRAL_DIRECTORY_RECORD_FIXED_SIZE);
509+
var fixedSizeStuff = Buffer.alloc(CENTRAL_DIRECTORY_RECORD_FIXED_SIZE);
510510
var generalPurposeBitFlag = FILE_NAME_IS_UTF8;
511511
if (!this.crcAndFileSizeKnown) generalPurposeBitFlag |= UNKNOWN_CRC32_AND_FILE_SIZES;
512512

@@ -522,7 +522,7 @@ Entry.prototype.getCentralDirectoryRecord = function() {
522522
versionNeededToExtract = VERSION_NEEDED_TO_EXTRACT_ZIP64;
523523

524524
// ZIP64 extended information extra field
525-
zeiefBuffer = new Buffer(ZIP64_EXTENDED_INFORMATION_EXTRA_FIELD_SIZE);
525+
zeiefBuffer = Buffer.alloc(ZIP64_EXTENDED_INFORMATION_EXTRA_FIELD_SIZE);
526526
// 0x0001 2 bytes Tag for this "extra" block type
527527
zeiefBuffer.writeUInt16LE(0x0001, 0);
528528
// Size 2 bytes Size of this "extra" block
@@ -537,7 +537,7 @@ Entry.prototype.getCentralDirectoryRecord = function() {
537537
// (omit)
538538
} else {
539539
versionNeededToExtract = VERSION_NEEDED_TO_EXTRACT_UTF8;
540-
zeiefBuffer = new Buffer(0);
540+
zeiefBuffer = Buffer.alloc(0);
541541
}
542542

543543
// 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)