diff --git a/README.md b/README.md index b9bc9d1..e2136e6 100644 --- a/README.md +++ b/README.md @@ -96,11 +96,13 @@ var output = inflator.result; Notes ----- -Pako does not contains some very specific zlib functions. +Pako does not contains some specific zlib functions: -- __deflate__ - writing bustom gzip headers and methods `deflateSetDictionary`, +- __deflate__ - writing custom gzip headers and methods `deflateSetDictionary`, `deflateParams`, `deflateSetHeader`, `deflateBound`, `deflatePending`. -- __inflate__ - TBD. +- __inflate__ - getting custom gzip headers and methods `inflateGetDictionary`, + `inflateGetHeader`, `inflateSetDictionary`, `inflateSync`, `inflateSyncPoint`, + `inflateCopy`, `inflateUndermine`, `inflateMark`. Authors diff --git a/lib/deflate.js b/lib/deflate.js index bf5060c..97a18f4 100644 --- a/lib/deflate.js +++ b/lib/deflate.js @@ -244,7 +244,7 @@ Deflate.prototype.onEnd = function(status) { } this.chunks = []; this.err = status; - this.msg = msg[status]; + this.msg = this.strm.msg; }; @@ -280,7 +280,7 @@ function deflate(input, options) { deflator.push(input, true); // That will never happens, if you don't cheat with options :) - if (deflator.err) { throw msg[deflator.err]; } + if (deflator.err) { throw deflator.msg; } return deflator.result; } diff --git a/lib/inflate.js b/lib/inflate.js index 23a6753..8cf8695 100644 --- a/lib/inflate.js +++ b/lib/inflate.js @@ -61,6 +61,9 @@ var zstream = require('./zlib/zstream'); * - `chunkSize` - size of generated data chunks (16K by default) * - `raw` (boolean) - do raw inflate * + * By default, when no options set, autodetect deflate/gzip data format via + * wrapper header. + * * ##### Example: * * ```javascript @@ -87,8 +90,8 @@ var Inflate = function(options) { var opt = this.options; - // check `raw` if `windowBits` NOT defined directly, - // or we will get bug because of autodetect + // Force window size for `raw` data, if not set directly, + // because we have no header for autodetect. if (opt.raw && (opt.windowBits >= 0) && (opt.windowBits < 16)) { opt.windowBits = -opt.windowBits; if (opt.windowBits === 0) { opt.windowBits = -15; } @@ -228,7 +231,7 @@ Inflate.prototype.onEnd = function(status) { } this.chunks = []; this.err = status; - this.msg = msg[status]; + this.msg = this.strm.msg; }; @@ -237,14 +240,22 @@ Inflate.prototype.onEnd = function(status) { * - data (Uint8Array|Array): input data to compress. * - options (Object): zlib inflate options. * - * Decompress `data` with inflate alrorythm and `options`. + * Decompress `data` with inflate/ungzip and `options`. Autodetect + * format via wrapper header by default. That's why we don't provide + * separate `ungzip` method. * * Supported options are: * * - windowBits * * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced) - * for more information on these. + * for more information. + * + * Sugar (options): + * + * - raw (Boolean) - say that we work with raw stream, if you don't wish to specify + * negative windowBits implicitly. + * * * ##### Example: * @@ -266,7 +277,7 @@ function inflate(input, options) { inflator.push(input, true); // That will never happens, if you don't cheat with options :) - if (inflator.err) { throw msg[inflator.err]+':'+inflator.strm.msg; } + if (inflator.err) { throw inflator.msg; } return inflator.result; } diff --git a/lib/zlib/deflate.js b/lib/zlib/deflate.js index 10e312e..435ceae 100644 --- a/lib/zlib/deflate.js +++ b/lib/zlib/deflate.js @@ -103,9 +103,9 @@ var BS_FINISH_DONE = 4; /* finish done, accept no more input or output */ var OS_CODE = 0x03; // Unix :) . Don't detect, use this default. -function err(strm, error) { - strm.msg = msg[error]; - return error; +function err(strm, errorCode) { + strm.msg = msg[errorCode]; + return errorCode; } function rank(f) { diff --git a/test/inflate.js b/test/inflate.js index 94cfac3..94c9e8b 100644 --- a/test/inflate.js +++ b/test/inflate.js @@ -25,9 +25,6 @@ describe('Inflate defaults', function () { describe('Inflate ungzip', function () { - // TODO: Investigate, why ungzip does not autodetect window size and - // require to set windowBits directly - it('with autodetect', function(done) { testInflate(samples, {}, { gzip: true }, done); });