Skip to content

Commit

Permalink
Merge branch 'master' into comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mojodna committed Nov 15, 2018
2 parents e8c32f8 + 6ee7c2e commit 09a58cf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 28 deletions.
14 changes: 4 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,8 @@ zipfile.outputStream.pipe(fs.createWriteStream("output.zip")).on("close", functi
console.log("done");
});
// alternate apis for adding files:
zipfile.addReadStream(process.stdin, "stdin.txt", {
mtime: new Date(),
mode: parseInt("0100664", 8), // -rw-rw-r--
});
zipfile.addBuffer(new Buffer("hello"), "hello.txt", {
mtime: new Date(),
mode: parseInt("0100664", 8), // -rw-rw-r--
});
zipfile.addReadStream(process.stdin, "stdin.txt");
zipfile.addBuffer(Buffer.from("hello"), "hello.txt");
// call end() after all the files have been added
zipfile.end();
```
Expand Down Expand Up @@ -101,7 +95,7 @@ See `addFile()` for info about the `metadataPath` parameter.
```js
{
mtime: new Date(),
mode: parseInt("0100664", 8),
mode: 0o100664,
compress: true,
forceZip64Format: false,
fileComment: "",
Expand All @@ -126,7 +120,7 @@ See `addFile()` for info about the `metadataPath` parameter.
```js
{
mtime: new Date(),
mode: parseInt("0100664", 8),
mode: 0o100664,
compress: true,
forceZip64Format: false,
fileComment: ""
Expand Down
27 changes: 12 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ function getEndOfCentralDirectoryRecord(self, actuallyJustTellMeHowLongItWouldBe
}
}

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

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


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

var defaultFileMode = parseInt("0100664", 8);
var defaultDirectoryMode = parseInt("040775", 8);

// this class is not part of the public API
function Entry(metadataPath, isDirectory, options) {
this.utf8FileName = new Buffer(metadataPath);
this.utf8FileName = Buffer.from(metadataPath);
if (this.utf8FileName.length > 0xffff) throw new Error("utf8 file name too long. " + utf8FileName.length + " > " + 0xffff);
this.isDirectory = isDirectory;
this.state = Entry.WAITING_FOR_METADATA;
this.setLastModDate(options.mtime != null ? options.mtime : new Date());
if (options.mode != null) {
this.setFileAttributesMode(options.mode);
} else {
this.setFileAttributesMode(isDirectory ? defaultDirectoryMode : defaultFileMode);
this.setFileAttributesMode(isDirectory ? 0o40775 : 0o100664);
}
if (isDirectory) {
this.crcAndFileSizeKnown = true;
Expand Down Expand Up @@ -442,7 +439,7 @@ Entry.prototype.getLocalFileHeader = function() {
uncompressedSize = this.uncompressedSize;
}

var fixedSizeStuff = new Buffer(LOCAL_FILE_HEADER_FIXED_SIZE);
var fixedSizeStuff = Buffer.allocUnsafe(LOCAL_FILE_HEADER_FIXED_SIZE);
var generalPurposeBitFlag = FILE_NAME_IS_UTF8;
if (!this.crcAndFileSizeKnown) generalPurposeBitFlag |= UNKNOWN_CRC32_AND_FILE_SIZES;

Expand Down Expand Up @@ -481,10 +478,10 @@ var ZIP64_DATA_DESCRIPTOR_SIZE = 24;
Entry.prototype.getDataDescriptor = function() {
if (this.crcAndFileSizeKnown) {
// the Mac Archive Utility requires this not be present unless we set general purpose bit 3
return new Buffer(0);
return Buffer.allocUnsafe(0);
}
if (!this.useZip64Format()) {
var buffer = new Buffer(DATA_DESCRIPTOR_SIZE);
var buffer = Buffer.allocUnsafe(DATA_DESCRIPTOR_SIZE);
// optional signature (required according to Archive Utility)
buffer.writeUInt32LE(0x08074b50, 0);
// crc-32 4 bytes
Expand All @@ -496,7 +493,7 @@ Entry.prototype.getDataDescriptor = function() {
return buffer;
} else {
// ZIP64 format
var buffer = new Buffer(ZIP64_DATA_DESCRIPTOR_SIZE);
var buffer = Buffer.allocUnsafe(ZIP64_DATA_DESCRIPTOR_SIZE);
// optional signature (unknown if anyone cares about this)
buffer.writeUInt32LE(0x08074b50, 0);
// crc-32 4 bytes
Expand All @@ -511,7 +508,7 @@ Entry.prototype.getDataDescriptor = function() {
var CENTRAL_DIRECTORY_RECORD_FIXED_SIZE = 46;
var ZIP64_EXTENDED_INFORMATION_EXTRA_FIELD_SIZE = 28;
Entry.prototype.getCentralDirectoryRecord = function() {
var fixedSizeStuff = new Buffer(CENTRAL_DIRECTORY_RECORD_FIXED_SIZE);
var fixedSizeStuff = Buffer.allocUnsafe(CENTRAL_DIRECTORY_RECORD_FIXED_SIZE);
var generalPurposeBitFlag = FILE_NAME_IS_UTF8;
if (!this.crcAndFileSizeKnown) generalPurposeBitFlag |= UNKNOWN_CRC32_AND_FILE_SIZES;

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

// ZIP64 extended information extra field
zeiefBuffer = new Buffer(ZIP64_EXTENDED_INFORMATION_EXTRA_FIELD_SIZE);
zeiefBuffer = Buffer.allocUnsafe(ZIP64_EXTENDED_INFORMATION_EXTRA_FIELD_SIZE);
// 0x0001 2 bytes Tag for this "extra" block type
zeiefBuffer.writeUInt16LE(0x0001, 0);
// Size 2 bytes Size of this "extra" block
Expand All @@ -542,7 +539,7 @@ Entry.prototype.getCentralDirectoryRecord = function() {
// (omit)
} else {
versionNeededToExtract = VERSION_NEEDED_TO_EXTRACT_UTF8;
zeiefBuffer = new Buffer(0);
zeiefBuffer = Buffer.allocUnsafe(0);
}

// central file header signature 4 bytes (0x02014b50)
Expand Down
6 changes: 3 additions & 3 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var BufferList = require("bl");
options.forceZip64Format = !!zip64Config[1];
zipfile.addFile(__filename, "fdsa.txt", options);
options.forceZip64Format = !!zip64Config[2];
zipfile.addBuffer(new Buffer("buffer"), "buffer.txt", options);
zipfile.addBuffer(Buffer.from("buffer"), "buffer.txt", options);
options.forceZip64Format = !!zip64Config[3];
options.size = "stream".length;
zipfile.addReadStream(new BufferList().append("stream"), "stream.txt", options);
Expand All @@ -76,7 +76,7 @@ var BufferList = require("bl");
var zipfile = new yazl.ZipFile();
// all options parameters are optional
zipfile.addFile(__filename, "a.txt");
zipfile.addBuffer(new Buffer("buffer"), "b.txt");
zipfile.addBuffer(Buffer.from("buffer"), "b.txt");
zipfile.addReadStream(new BufferList().append("stream"), "c.txt");
zipfile.addEmptyDirectory("d/");
zipfile.addEmptyDirectory("e");
Expand Down Expand Up @@ -104,7 +104,7 @@ var BufferList = require("bl");
(function() {
var zipfile = new yazl.ZipFile();
// all options parameters are optional
zipfile.addBuffer(new Buffer("hello"), "hello.txt", {compress: false});
zipfile.addBuffer(Buffer.from("hello"), "hello.txt", {compress: false});
zipfile.end(function(finalSize) {
if (finalSize === -1) throw new Error("finalSize should be known");
zipfile.outputStream.pipe(new BufferList(function(err, data) {
Expand Down

0 comments on commit 09a58cf

Please sign in to comment.