better docs/works with errors/messages

This commit is contained in:
Vitaly Puzrin 2014-02-20 21:29:22 +04:00
parent eb234788e0
commit f733a66266
3 changed files with 29 additions and 12 deletions

View file

@ -45,12 +45,19 @@ function sliceBuf(buf, size) {
* custom handlers. * custom handlers.
**/ **/
/**
* Deflate.msg -> String
*
* Error message, if [[Deflate.err]] != 0
**/
/** /**
* new Deflate(options) * new Deflate(options)
* - options (Object): zlib 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` * - `level`
* - `windowBits` * - `windowBits`
@ -104,8 +111,10 @@ var Deflate = function(options) {
opt.windowBits += 16; opt.windowBits += 16;
} }
this.ended = false; // used to avoid multiple onEnd() calls this.err = 0; // error code, if happens (0 = Z_OK)
this.chunks = []; // chunks of compressed data 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();
@ -224,8 +233,7 @@ Deflate.prototype.onEnd = function(status) {
} }
this.chunks = []; this.chunks = [];
this.err = status; this.err = status;
// TODO: detect message by status, if not set in zstream this.msg = msg[status];
this.msg = this.strm.msg || msg[status];
}; };

View file

@ -43,12 +43,19 @@ function sliceBuf(buf, size) {
* Should be checked if broken data possible. * Should be checked if broken data possible.
**/ **/
/**
* Inflate.msg -> String
*
* Error message, if [[Inflate.err]] != 0
**/
/** /**
* new Inflate(options) * new Inflate(options)
* - options (Object): zlib 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` * - `windowBits`
* *
@ -90,12 +97,14 @@ var Inflate = function(options) {
opt.windowBits = -opt.windowBits; opt.windowBits = -opt.windowBits;
} }
this.ended = false; // used to avoid multiple onEnd() calls this.err = 0; // error code, if happens (0 = Z_OK)
this.chunks = []; // chunks of compressed data 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, this.strm,
opt.windowBits opt.windowBits
); );
@ -206,8 +215,7 @@ Inflate.prototype.onEnd = function(status) {
} }
this.chunks = []; this.chunks = [];
this.err = status; this.err = status;
// TODO: detect message by status, if not set in zstream this.msg = msg[status];
this.msg = this.strm.msg || msg[status];
}; };

View file

@ -2,6 +2,7 @@
var c = require('constants'); var c = require('constants');
// TODO: remove Z_NULL. Set proper values directly
function ZStream() { function ZStream() {
/* next input byte */ /* next input byte */
this.next_in = c.Z_NULL; this.next_in = c.Z_NULL;