mirror of
https://github.com/0x5eal/rbxts-pako.git
synced 2025-04-21 12:24:00 +01:00
add message to ZStream on deflate error
This commit is contained in:
parent
07173737fc
commit
9f495b8b13
2 changed files with 15 additions and 10 deletions
|
@ -4,6 +4,7 @@ var utils = require('./utils');
|
||||||
var trees = require('./trees');
|
var trees = require('./trees');
|
||||||
var adler32 = require('./adler32');
|
var adler32 = require('./adler32');
|
||||||
var crc32 = require('./crc32');
|
var crc32 = require('./crc32');
|
||||||
|
var msg = require('./messages');
|
||||||
|
|
||||||
/* Public constants ==========================================================*/
|
/* 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.
|
var OS_CODE = 0x03; // Unix :) . Don't detect, use this default.
|
||||||
|
|
||||||
|
function err(strm, error) {
|
||||||
|
strm.msg = msg[error];
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
function rank(f) {
|
function rank(f) {
|
||||||
return ((f) << 1) - ((f) > 4 ? 9 : 0);
|
return ((f) << 1) - ((f) > 4 ? 9 : 0);
|
||||||
|
@ -1261,7 +1266,7 @@ function deflateResetKeep(strm) {
|
||||||
var s;
|
var s;
|
||||||
|
|
||||||
if (!strm || !strm.state) {
|
if (!strm || !strm.state) {
|
||||||
return Z_STREAM_ERROR;
|
return err(strm, Z_STREAM_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
strm.total_in = strm.total_out = 0;
|
strm.total_in = strm.total_out = 0;
|
||||||
|
@ -1295,7 +1300,7 @@ function deflateReset(strm) {
|
||||||
|
|
||||||
function deflateInit2(strm, level, method, windowBits, memLevel, strategy) {
|
function deflateInit2(strm, level, method, windowBits, memLevel, strategy) {
|
||||||
if (!strm) { // === Z_NULL
|
if (!strm) { // === Z_NULL
|
||||||
return Z_STREAM_ERROR;
|
return err(strm, Z_STREAM_ERROR);
|
||||||
}
|
}
|
||||||
var wrap = 1;
|
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 ||
|
if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method !== Z_DEFLATED ||
|
||||||
windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
|
windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
|
||||||
strategy < 0 || strategy > Z_FIXED) {
|
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 ||
|
if (!strm || !strm.state ||
|
||||||
flush > Z_BLOCK || flush < 0) {
|
flush > Z_BLOCK || flush < 0) {
|
||||||
return Z_STREAM_ERROR;
|
return err(strm, Z_STREAM_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
s = strm.state;
|
s = strm.state;
|
||||||
|
@ -1381,7 +1386,7 @@ function deflate(strm, flush) {
|
||||||
if (!strm.next_out ||
|
if (!strm.next_out ||
|
||||||
(!strm.next_in && strm.avail_in !== 0) ||
|
(!strm.next_in && strm.avail_in !== 0) ||
|
||||||
(s.status === FINISH_STATE && flush !== Z_FINISH)) {
|
(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 */
|
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) &&
|
} else if (strm.avail_in === 0 && rank(flush) <= rank(old_flush) &&
|
||||||
flush !== Z_FINISH) {
|
flush !== Z_FINISH) {
|
||||||
return Z_BUF_ERROR;
|
return err(strm, Z_BUF_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* User must not provide more input after the first FINISH: */
|
/* User must not provide more input after the first FINISH: */
|
||||||
if (s.status === FINISH_STATE && strm.avail_in !== 0) {
|
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.
|
/* Start a new block or continue the current one.
|
||||||
|
@ -1565,12 +1570,12 @@ function deflateEnd(strm) {
|
||||||
status !== BUSY_STATE &&
|
status !== BUSY_STATE &&
|
||||||
status !== FINISH_STATE
|
status !== FINISH_STATE
|
||||||
) {
|
) {
|
||||||
return Z_STREAM_ERROR;
|
return err(strm, Z_STREAM_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
strm.state = null;
|
strm.state = null;
|
||||||
|
|
||||||
return status === BUSY_STATE ? Z_DATA_ERROR : Z_OK;
|
return status === BUSY_STATE ? err(strm, Z_DATA_ERROR) : Z_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* =========================================================================
|
/* =========================================================================
|
||||||
|
|
|
@ -17,7 +17,7 @@ function ZStream() {
|
||||||
/* total number of bytes output so far */
|
/* total number of bytes output so far */
|
||||||
this.total_out = 0;
|
this.total_out = 0;
|
||||||
/* last error message, NULL if no error */
|
/* last error message, NULL if no error */
|
||||||
this.msg = ''/*Z_NULL*/; // for inflate only
|
this.msg = ''/*Z_NULL*/;
|
||||||
/* not visible by applications */
|
/* not visible by applications */
|
||||||
this.state = null;
|
this.state = null;
|
||||||
/* best guess about the data type: binary or text */
|
/* best guess about the data type: binary or text */
|
||||||
|
|
Loading…
Add table
Reference in a new issue