Introduce deflateFactory option to packer

The main application motivating this addition is the creation of
reproducible compression results.  Since `zlib` is shipped with node.js, we
have no control over its version via npm.  To guarantee reproducible
results, other libraries (like pako) could be used, with a fixed version
number to guarantee consistent behavior.  This modification provides a hook
to allow such usage.
This commit is contained in:
Martin von Gagern 2015-08-28 09:36:34 +02:00
parent 7f456bacda
commit a0596a58c4
2 changed files with 3 additions and 1 deletions

View file

@ -110,6 +110,7 @@ As input any color type is accepted (grayscale, rgb, palette, grayscale with alp
- `deflateChunkSize` - chunk size used for deflating data chunks, this should be power of 2 and must not be less than 256 and more than 32*1024 (default: 32 kB)
- `deflateLevel` - compression level for delate (default: 9)
- `deflateStrategy` - compression strategy for delate (default: 3)
- `deflateFactory` - deflate stream factory (default: `zlib.createDeflate`)
- `filterType` - png filtering method for scanlines (default: -1 => auto, accepts array of numbers 0-4)

View file

@ -17,6 +17,7 @@ var Packer = module.exports = function(options) {
options.deflateChunkSize = options.deflateChunkSize || 32 * 1024;
options.deflateLevel = options.deflateLevel != null ? options.deflateLevel : 9;
options.deflateStrategy = options.deflateStrategy != null ? options.deflateStrategy : 3;
options.deflateFactory = options.deflateFactory || zlib.createDeflate;
this.readable = true;
};
@ -37,7 +38,7 @@ Packer.prototype.pack = function(data, width, height, gamma) {
var filteredData = filter(data, width, height, this._options);
// compress it
var deflate = zlib.createDeflate({
var deflate = this._options.deflateFactory({
chunkSize: this._options.deflateChunkSize,
level: this._options.deflateLevel,
strategy: this._options.deflateStrategy