@@ -108,14 +108,18 @@ function _make(isCompress, type, options = {}) {
108108 }
109109 heap . set ( buffer . subarray ( offset , offset + toRead ) , this . in ) ;
110110 const result = process ( this . streamHandle , this . in , toRead , out , outBufferSize , 0 ) ;
111- if ( ! isCompress && result < 0 ) {
112- throw new Error ( "process error:" + result ) ;
113- }
114111 const prod = result & 0x00ffffff ;
115112 if ( prod ) {
116113 scratch . set ( heap . subarray ( out , out + prod ) , 0 ) ;
117114 controller . enqueue ( scratch . slice ( 0 , prod ) ) ;
118115 }
116+ if ( ! isCompress ) {
117+ const code = ( result >> 24 ) & 0xff ;
118+ const signedCode = ( code & 0x80 ) ? code - 256 : code ;
119+ if ( signedCode < 0 ) {
120+ throw new Error ( "process error:" + signedCode ) ;
121+ }
122+ }
119123 const consumed = last_consumed ( this . streamHandle ) ;
120124 if ( consumed === 0 ) {
121125 break ;
@@ -143,11 +147,14 @@ function _make(isCompress, type, options = {}) {
143147 const scratch = this . _scratch ;
144148 while ( true ) {
145149 const result = process ( this . streamHandle , 0 , 0 , out , outBufferSize , 4 ) ;
146- if ( ! isCompress && result < 0 ) {
147- throw new Error ( "process error:" + result ) ;
148- }
149150 const produced = result & 0x00ffffff ;
150151 const code = ( result >> 24 ) & 0xff ;
152+ if ( ! isCompress ) {
153+ const signedCode = ( code & 0x80 ) ? code - 256 : code ;
154+ if ( signedCode < 0 ) {
155+ throw new Error ( "process error:" + signedCode ) ;
156+ }
157+ }
151158 if ( produced ) {
152159 scratch . set ( heap . subarray ( out , out + produced ) , 0 ) ;
153160 controller . enqueue ( scratch . slice ( 0 , produced ) ) ;
0 commit comments