From f733a662667e31c9920ab0b619321915dbd4ca9d Mon Sep 17 00:00:00 2001 From: Vitaly Puzrin Date: Thu, 20 Feb 2014 21:29:22 +0400 Subject: [PATCH] better docs/works with errors/messages --- lib/deflate.js | 18 +++++++++++++----- lib/inflate.js | 22 +++++++++++++++------- lib/zlib/zstream.js | 1 + 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/lib/deflate.js b/lib/deflate.js index ce29e7d..96db340 100644 --- a/lib/deflate.js +++ b/lib/deflate.js @@ -45,12 +45,19 @@ function sliceBuf(buf, size) { * custom handlers. **/ +/** + * Deflate.msg -> String + * + * Error message, if [[Deflate.err]] != 0 + **/ + /** * new Deflate(options) * - options (Object): zlib deflate options. * - * Creates new deflator instance with specified params. Supported options: + * Creates new deflator instance with specified params. Throws exception + * on bad params. Supported options: * * - `level` * - `windowBits` @@ -104,8 +111,10 @@ var Deflate = function(options) { opt.windowBits += 16; } - this.ended = false; // used to avoid multiple onEnd() calls - this.chunks = []; // chunks of compressed data + this.err = 0; // error code, if happens (0 = Z_OK) + this.msg = ''; // error message + this.ended = false; // used to avoid multiple onEnd() calls + this.chunks = []; // chunks of compressed data this.strm = new zstream(); @@ -224,8 +233,7 @@ Deflate.prototype.onEnd = function(status) { } this.chunks = []; this.err = status; - // TODO: detect message by status, if not set in zstream - this.msg = this.strm.msg || msg[status]; + this.msg = msg[status]; }; diff --git a/lib/inflate.js b/lib/inflate.js index 5c351ae..43abaa8 100644 --- a/lib/inflate.js +++ b/lib/inflate.js @@ -43,12 +43,19 @@ function sliceBuf(buf, size) { * Should be checked if broken data possible. **/ +/** + * Inflate.msg -> String + * + * Error message, if [[Inflate.err]] != 0 + **/ + /** * new Inflate(options) * - options (Object): zlib inflate options. * - * Creates new inflator instance with specified params. Supported options: + * Creates new inflator instance with specified params. Throws exception + * on bad params. Supported options: * * - `windowBits` * @@ -90,12 +97,14 @@ var Inflate = function(options) { opt.windowBits = -opt.windowBits; } - this.ended = false; // used to avoid multiple onEnd() calls - this.chunks = []; // chunks of compressed data + this.err = 0; // error code, if happens (0 = Z_OK) + this.msg = ''; // error message + this.ended = false; // used to avoid multiple onEnd() calls + this.chunks = []; // chunks of compressed data - this.strm = new zstream(); + this.strm = new zstream(); - var status = zlib_inflate.inflateInit2( + var status = zlib_inflate.inflateInit2( this.strm, opt.windowBits ); @@ -206,8 +215,7 @@ Inflate.prototype.onEnd = function(status) { } this.chunks = []; this.err = status; - // TODO: detect message by status, if not set in zstream - this.msg = this.strm.msg || msg[status]; + this.msg = msg[status]; }; diff --git a/lib/zlib/zstream.js b/lib/zlib/zstream.js index 162dc55..f7d32d9 100644 --- a/lib/zlib/zstream.js +++ b/lib/zlib/zstream.js @@ -2,6 +2,7 @@ var c = require('constants'); +// TODO: remove Z_NULL. Set proper values directly function ZStream() { /* next input byte */ this.next_in = c.Z_NULL;