diff --git a/lib/zlib/deflate.js b/lib/zlib/deflate.js index 8df5613..10e312e 100644 --- a/lib/zlib/deflate.js +++ b/lib/zlib/deflate.js @@ -4,6 +4,7 @@ var utils = require('./utils'); var trees = require('./trees'); var adler32 = require('./adler32'); var crc32 = require('./crc32'); +var msg = require('./messages'); /* Public constants ==========================================================*/ /* ===========================================================================*/ @@ -102,6 +103,10 @@ 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 rank(f) { return ((f) << 1) - ((f) > 4 ? 9 : 0); @@ -1261,7 +1266,7 @@ function deflateResetKeep(strm) { var s; if (!strm || !strm.state) { - return Z_STREAM_ERROR; + return err(strm, Z_STREAM_ERROR); } strm.total_in = strm.total_out = 0; @@ -1295,7 +1300,7 @@ function deflateReset(strm) { function deflateInit2(strm, level, method, windowBits, memLevel, strategy) { if (!strm) { // === Z_NULL - return Z_STREAM_ERROR; + return err(strm, Z_STREAM_ERROR); } var wrap = 1; @@ -1317,7 +1322,7 @@ function deflateInit2(strm, level, method, windowBits, memLevel, strategy) { if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method !== Z_DEFLATED || windowBits < 8 || windowBits > 15 || level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) { - return Z_STREAM_ERROR; + return err(strm, Z_STREAM_ERROR); } @@ -1373,7 +1378,7 @@ function deflate(strm, flush) { if (!strm || !strm.state || flush > Z_BLOCK || flush < 0) { - return Z_STREAM_ERROR; + return err(strm, Z_STREAM_ERROR); } s = strm.state; @@ -1381,7 +1386,7 @@ function deflate(strm, flush) { if (!strm.next_out || (!strm.next_in && strm.avail_in !== 0) || (s.status === FINISH_STATE && flush !== Z_FINISH)) { - return (strm.avail_out === 0) ? Z_BUF_ERROR : Z_STREAM_ERROR; + return err(strm, (strm.avail_out === 0) ? Z_BUF_ERROR : Z_STREAM_ERROR); } s.strm = strm; /* just in case */ @@ -1462,12 +1467,12 @@ function deflate(strm, flush) { */ } else if (strm.avail_in === 0 && rank(flush) <= rank(old_flush) && flush !== Z_FINISH) { - return Z_BUF_ERROR; + return err(strm, Z_BUF_ERROR); } /* User must not provide more input after the first FINISH: */ if (s.status === FINISH_STATE && strm.avail_in !== 0) { - return Z_BUF_ERROR; + return err(strm, Z_BUF_ERROR); } /* Start a new block or continue the current one. @@ -1565,12 +1570,12 @@ function deflateEnd(strm) { status !== BUSY_STATE && status !== FINISH_STATE ) { - return Z_STREAM_ERROR; + return err(strm, Z_STREAM_ERROR); } strm.state = null; - return status === BUSY_STATE ? Z_DATA_ERROR : Z_OK; + return status === BUSY_STATE ? err(strm, Z_DATA_ERROR) : Z_OK; } /* ========================================================================= diff --git a/lib/zlib/zstream.js b/lib/zlib/zstream.js index 12e8b02..d9d5265 100644 --- a/lib/zlib/zstream.js +++ b/lib/zlib/zstream.js @@ -17,7 +17,7 @@ function ZStream() { /* total number of bytes output so far */ this.total_out = 0; /* last error message, NULL if no error */ - this.msg = ''/*Z_NULL*/; // for inflate only + this.msg = ''/*Z_NULL*/; /* not visible by applications */ this.state = null; /* best guess about the data type: binary or text */