Skip to content

Commit 09a58cf

Browse files
authored
Merge branch 'master' into comments
2 parents e8c32f8 + 6ee7c2e commit 09a58cf

File tree

3 files changed

+19
-28
lines changed

3 files changed

+19
-28
lines changed

README.md

+4-10
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,8 @@ zipfile.outputStream.pipe(fs.createWriteStream("output.zip")).on("close", functi
2727
console.log("done");
2828
});
2929
// alternate apis for adding files:
30-
zipfile.addReadStream(process.stdin, "stdin.txt", {
31-
mtime: new Date(),
32-
mode: parseInt("0100664", 8), // -rw-rw-r--
33-
});
34-
zipfile.addBuffer(new Buffer("hello"), "hello.txt", {
35-
mtime: new Date(),
36-
mode: parseInt("0100664", 8), // -rw-rw-r--
37-
});
30+
zipfile.addReadStream(process.stdin, "stdin.txt");
31+
zipfile.addBuffer(Buffer.from("hello"), "hello.txt");
3832
// call end() after all the files have been added
3933
zipfile.end();
4034
```
@@ -101,7 +95,7 @@ See `addFile()` for info about the `metadataPath` parameter.
10195
```js
10296
{
10397
mtime: new Date(),
104-
mode: parseInt("0100664", 8),
98+
mode: 0o100664,
10599
compress: true,
106100
forceZip64Format: false,
107101
fileComment: "",
@@ -126,7 +120,7 @@ See `addFile()` for info about the `metadataPath` parameter.
126120
```js
127121
{
128122
mtime: new Date(),
129-
mode: parseInt("0100664", 8),
123+
mode: 0o100664,
130124
compress: true,
131125
forceZip64Format: false,
132126
fileComment: ""

index.js

+12-15
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ function getEndOfCentralDirectoryRecord(self, actuallyJustTellMeHowLongItWouldBe
278278
}
279279
}
280280

281-
var eocdrBuffer = Buffer.alloc(END_OF_CENTRAL_DIRECTORY_RECORD_SIZE + self.comment.length);
281+
var eocdrBuffer = Buffer.allocUnsafe(END_OF_CENTRAL_DIRECTORY_RECORD_SIZE + self.comment.length);
282282
// end of central dir signature 4 bytes (0x06054b50)
283283
eocdrBuffer.writeUInt32LE(0x06054b50, 0);
284284
// number of this disk 2 bytes
@@ -302,7 +302,7 @@ function getEndOfCentralDirectoryRecord(self, actuallyJustTellMeHowLongItWouldBe
302302

303303
// ZIP64 format
304304
// ZIP64 End of Central Directory Record
305-
var zip64EocdrBuffer = new Buffer(ZIP64_END_OF_CENTRAL_DIRECTORY_RECORD_SIZE);
305+
var zip64EocdrBuffer = Buffer.allocUnsafe(ZIP64_END_OF_CENTRAL_DIRECTORY_RECORD_SIZE);
306306
// zip64 end of central dir signature 4 bytes (0x06064b50)
307307
zip64EocdrBuffer.writeUInt32LE(0x06064b50, 0);
308308
// size of zip64 end of central directory record 8 bytes
@@ -328,7 +328,7 @@ function getEndOfCentralDirectoryRecord(self, actuallyJustTellMeHowLongItWouldBe
328328

329329

330330
// ZIP64 End of Central Directory Locator
331-
var zip64EocdlBuffer = new Buffer(ZIP64_END_OF_CENTRAL_DIRECTORY_LOCATOR_SIZE);
331+
var zip64EocdlBuffer = Buffer.allocUnsafe(ZIP64_END_OF_CENTRAL_DIRECTORY_LOCATOR_SIZE);
332332
// zip64 end of central dir locator signature 4 bytes (0x07064b50)
333333
zip64EocdlBuffer.writeUInt32LE(0x07064b50, 0);
334334
// number of the disk with the start of the zip64 end of central directory 4 bytes
@@ -361,20 +361,17 @@ function validateMetadataPath(metadataPath, isDirectory) {
361361
return metadataPath;
362362
}
363363

364-
var defaultFileMode = parseInt("0100664", 8);
365-
var defaultDirectoryMode = parseInt("040775", 8);
366-
367364
// this class is not part of the public API
368365
function Entry(metadataPath, isDirectory, options) {
369-
this.utf8FileName = new Buffer(metadataPath);
366+
this.utf8FileName = Buffer.from(metadataPath);
370367
if (this.utf8FileName.length > 0xffff) throw new Error("utf8 file name too long. " + utf8FileName.length + " > " + 0xffff);
371368
this.isDirectory = isDirectory;
372369
this.state = Entry.WAITING_FOR_METADATA;
373370
this.setLastModDate(options.mtime != null ? options.mtime : new Date());
374371
if (options.mode != null) {
375372
this.setFileAttributesMode(options.mode);
376373
} else {
377-
this.setFileAttributesMode(isDirectory ? defaultDirectoryMode : defaultFileMode);
374+
this.setFileAttributesMode(isDirectory ? 0o40775 : 0o100664);
378375
}
379376
if (isDirectory) {
380377
this.crcAndFileSizeKnown = true;
@@ -442,7 +439,7 @@ Entry.prototype.getLocalFileHeader = function() {
442439
uncompressedSize = this.uncompressedSize;
443440
}
444441

445-
var fixedSizeStuff = new Buffer(LOCAL_FILE_HEADER_FIXED_SIZE);
442+
var fixedSizeStuff = Buffer.allocUnsafe(LOCAL_FILE_HEADER_FIXED_SIZE);
446443
var generalPurposeBitFlag = FILE_NAME_IS_UTF8;
447444
if (!this.crcAndFileSizeKnown) generalPurposeBitFlag |= UNKNOWN_CRC32_AND_FILE_SIZES;
448445

@@ -481,10 +478,10 @@ var ZIP64_DATA_DESCRIPTOR_SIZE = 24;
481478
Entry.prototype.getDataDescriptor = function() {
482479
if (this.crcAndFileSizeKnown) {
483480
// the Mac Archive Utility requires this not be present unless we set general purpose bit 3
484-
return new Buffer(0);
481+
return Buffer.allocUnsafe(0);
485482
}
486483
if (!this.useZip64Format()) {
487-
var buffer = new Buffer(DATA_DESCRIPTOR_SIZE);
484+
var buffer = Buffer.allocUnsafe(DATA_DESCRIPTOR_SIZE);
488485
// optional signature (required according to Archive Utility)
489486
buffer.writeUInt32LE(0x08074b50, 0);
490487
// crc-32 4 bytes
@@ -496,7 +493,7 @@ Entry.prototype.getDataDescriptor = function() {
496493
return buffer;
497494
} else {
498495
// ZIP64 format
499-
var buffer = new Buffer(ZIP64_DATA_DESCRIPTOR_SIZE);
496+
var buffer = Buffer.allocUnsafe(ZIP64_DATA_DESCRIPTOR_SIZE);
500497
// optional signature (unknown if anyone cares about this)
501498
buffer.writeUInt32LE(0x08074b50, 0);
502499
// crc-32 4 bytes
@@ -511,7 +508,7 @@ Entry.prototype.getDataDescriptor = function() {
511508
var CENTRAL_DIRECTORY_RECORD_FIXED_SIZE = 46;
512509
var ZIP64_EXTENDED_INFORMATION_EXTRA_FIELD_SIZE = 28;
513510
Entry.prototype.getCentralDirectoryRecord = function() {
514-
var fixedSizeStuff = new Buffer(CENTRAL_DIRECTORY_RECORD_FIXED_SIZE);
511+
var fixedSizeStuff = Buffer.allocUnsafe(CENTRAL_DIRECTORY_RECORD_FIXED_SIZE);
515512
var generalPurposeBitFlag = FILE_NAME_IS_UTF8;
516513
if (!this.crcAndFileSizeKnown) generalPurposeBitFlag |= UNKNOWN_CRC32_AND_FILE_SIZES;
517514

@@ -527,7 +524,7 @@ Entry.prototype.getCentralDirectoryRecord = function() {
527524
versionNeededToExtract = VERSION_NEEDED_TO_EXTRACT_ZIP64;
528525

529526
// ZIP64 extended information extra field
530-
zeiefBuffer = new Buffer(ZIP64_EXTENDED_INFORMATION_EXTRA_FIELD_SIZE);
527+
zeiefBuffer = Buffer.allocUnsafe(ZIP64_EXTENDED_INFORMATION_EXTRA_FIELD_SIZE);
531528
// 0x0001 2 bytes Tag for this "extra" block type
532529
zeiefBuffer.writeUInt16LE(0x0001, 0);
533530
// Size 2 bytes Size of this "extra" block
@@ -542,7 +539,7 @@ Entry.prototype.getCentralDirectoryRecord = function() {
542539
// (omit)
543540
} else {
544541
versionNeededToExtract = VERSION_NEEDED_TO_EXTRACT_UTF8;
545-
zeiefBuffer = new Buffer(0);
542+
zeiefBuffer = Buffer.allocUnsafe(0);
546543
}
547544

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