Comparing version 3.1.0 to 3.2.0
25
index.js
@@ -94,6 +94,6 @@ var fs = require("fs"); | ||
self.entries.push(entry); | ||
if (!entry.compress) { | ||
if (entry.compressionLevel === 0) { | ||
setCompressedBuffer(buffer); | ||
} else { | ||
zlib.deflateRaw(buffer, function(err, compressedBuffer) { | ||
zlib.deflateRaw(buffer, {level:1}, function(err, compressedBuffer) { | ||
setCompressedBuffer(compressedBuffer); | ||
@@ -125,2 +125,3 @@ }); | ||
if (options.compress != null) throw new Error("options.compress not allowed"); | ||
if (options.compressionLevel != null) throw new Error("options.compressionLevel not allowed"); | ||
@@ -176,3 +177,3 @@ if (shouldIgnoreAdding(self)) return; | ||
var uncompressedSizeCounter = new ByteCounter(); | ||
var compressor = entry.compress ? new zlib.DeflateRaw() : new PassThrough(); | ||
var compressor = entry.compressionLevel !== 0 ? new zlib.DeflateRaw({level:entry.compressionLevel}) : new PassThrough(); | ||
var compressedSizeCounter = new ByteCounter(); | ||
@@ -199,2 +200,11 @@ readStream.pipe(crc32Watcher) | ||
function determineCompressionLevel(options) { | ||
if (options.compress != null && options.compressionLevel != null) { | ||
if (!!options.compress !== !!options.compressionLevel) throw new Error("conflicting settings for compress and compressionLevel"); | ||
} | ||
if (options.compressionLevel != null) return options.compressionLevel; | ||
if (options.compress === false) return 0; | ||
return 6; | ||
} | ||
function pumpEntries(self) { | ||
@@ -252,3 +262,3 @@ if (self.allDone || self.errored) return; | ||
// compression is too hard to predict | ||
if (entry.compress) return -1; | ||
if (entry.compressionLevel !== 0) return -1; | ||
if (entry.state >= Entry.READY_TO_PUMP_FILE_DATA) { | ||
@@ -444,6 +454,5 @@ // if addReadStream was called without providing the size, we can't predict the total size | ||
if (isDirectory) { | ||
this.compress = false; | ||
this.compressionLevel = 0; | ||
} else { | ||
this.compress = true; // default | ||
if (options.compress != null) this.compress = !!options.compress; | ||
this.compressionLevel = determineCompressionLevel(options); | ||
} | ||
@@ -659,3 +668,3 @@ this.forceZip64Format = !!options.forceZip64Format; | ||
var DEFLATE_COMPRESSION = 8; | ||
return this.compress ? DEFLATE_COMPRESSION : NO_COMPRESSION; | ||
return this.compressionLevel === 0 ? NO_COMPRESSION : DEFLATE_COMPRESSION; | ||
}; | ||
@@ -662,0 +671,0 @@ |
{ | ||
"name": "yazl", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"description": "yet another zip library for node", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -66,2 +66,3 @@ # yazl | ||
compress: true, | ||
compressionLevel: 6, | ||
forceZip64Format: false, | ||
@@ -81,2 +82,5 @@ fileComment: "", // or a UTF-8 Buffer | ||
If `compress` is `false`, the file data will be stored (compression method 0). | ||
If `compressionLevel` is specified, it will be passed to [`zlib`](https://nodejs.org/api/zlib.html#class-options). | ||
Specifying `compressionLevel: 0` is equivalent to `compress: false`. | ||
If both `compress` and `compressionLevel` are given, asserts that they do not conflict, i.e. `!!compress === !!compressionLevel`. | ||
@@ -125,2 +129,3 @@ If `forceZip64Format` is `true`, yazl will use ZIP64 format in this entry's Data Descriptor | ||
compress: true, | ||
compressionLevel: 6, | ||
forceZip64Format: false, | ||
@@ -132,5 +137,6 @@ fileComment: "", // or a UTF-8 Buffer | ||
See `addFile()` for the meaning of `mtime`, `mode`, `compress`, `forceZip64Format`, and `fileComment`. | ||
See `addFile()` for the meaning of `mtime`, `mode`, `compress`, `compressionLevel`, `forceZip64Format`, and `fileComment`. | ||
If `size` is given, it will be checked against the actual number of bytes in the `readStream`, | ||
and an error will be emitted if there is a mismatch. | ||
See the documentation on `calculatedTotalSizeCallback` for why the `size` option exists. | ||
@@ -161,2 +167,3 @@ Note that yazl will `.pipe()` data from `readStream`, so be careful using `.on('data')`. | ||
compress: true, | ||
compressionLevel: 6, | ||
forceZip64Format: false, | ||
@@ -167,3 +174,3 @@ fileComment: "", // or a UTF-8 Buffer | ||
See `addFile()` for the meaning of `mtime`, `mode`, `compress`, `forceZip64Format`, and `fileComment`. | ||
See `addFile()` for the meaning of `mtime`, `mode`, `compress`, `compressionLevel`, `forceZip64Format`, and `fileComment`. | ||
@@ -241,3 +248,3 @@ This method has the unique property that General Purpose Bit `3` will not be used in the Local File Header. | ||
If your string uses only codepoints in the range `0x20...0x7e` | ||
(printable ASCII, no whitespace except for sinlge space `' '`), | ||
(printable ASCII, no whitespace except for single space `' '`), | ||
then UTF-8 and CP437 (and ASCII) encodings are all identical. | ||
@@ -247,3 +254,2 @@ This restriction is recommended for maxium compatibility. | ||
If specified and non-null, `calculatedTotalSizeCallback` is given the parameters `(calculatedTotalSize)` | ||
@@ -262,6 +268,5 @@ sometime during or after the call to `end()`. | ||
If `calculatedTotalSize` is `-1`, it means means the total size is too hard to guess before processing the input file data. | ||
This will happen if and only if the `compress` option is `true` on any call to `addFile()`, `addReadStream()`, `addReadStreamLazy()`, `addBuffer()`, or `addEmptyDirectory()`, | ||
or if `addReadStream()` or `addReadStreamLazy()` is called and the optional `size` option is not given. | ||
In other words, clients should know whether they're going to get a `-1` or a real value | ||
by looking at how they are using this library. | ||
To ensure the final size is known, disable compression (set `compress: false` or `compressionLevel: 0`) | ||
in every call to `addFile()`, `addReadStream()`, `addReadStreamLazy()`, and `addBuffer()`, | ||
and additionally specify the optional `size` option in every call to `addReadStream()` and `addReadStreamLazy()`. | ||
@@ -391,2 +396,5 @@ The call to `calculatedTotalSizeCallback` might be delayed if yazl is still waiting for `fs.Stats` for an `addFile()` entry. | ||
* 3.2.0 (2024-Nov-02) | ||
* Add `compressionLevel` option to `addFile()`, `addBuffer()`, `addReadStream()`, `addReadStreamLazy()`. | ||
* Change wording around `calculatedTotalSizeCallback` again, and fix the documentation incorrectly claiming that `addEmptyDirectory()` was relevant in that context. | ||
* 3.1.0 (2024-Oct-19) | ||
@@ -393,0 +401,0 @@ * Add `addReadStreamLazy()` as a replacement for `addReadStream()`. The latter is maintained for compatibility and situational convenience. [issue #74](https://github.com/thejoshwolfe/yazl/issues/74) [pull #80](https://github.com/thejoshwolfe/yazl/pull/80) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53842
738
432