@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3636 return ( mod && mod . __esModule ) ? mod : { "default" : mod } ;
3737} ;
3838Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
39- exports . BrotliDecompress = exports . BrotliCompress = exports . Brotli = exports . Unzip = exports . InflateRaw = exports . DeflateRaw = exports . Gunzip = exports . Gzip = exports . Inflate = exports . Deflate = exports . Zlib = exports . ZlibError = exports . constants = void 0 ;
39+ exports . ZstdDecompress = exports . ZstdCompress = exports . BrotliDecompress = exports . BrotliCompress = exports . Unzip = exports . InflateRaw = exports . DeflateRaw = exports . Gunzip = exports . Gzip = exports . Inflate = exports . Deflate = exports . Zlib = exports . ZlibError = exports . constants = void 0 ;
4040const assert_1 = __importDefault ( require ( "assert" ) ) ;
4141const buffer_1 = require ( "buffer" ) ;
4242const minipass_1 = require ( "minipass" ) ;
@@ -56,15 +56,15 @@ const _superWrite = Symbol('_superWrite');
5656class ZlibError extends Error {
5757 code ;
5858 errno ;
59- constructor ( err ) {
60- super ( 'zlib: ' + err . message ) ;
59+ constructor ( err , origin ) {
60+ super ( 'zlib: ' + err . message , { cause : err } ) ;
6161 this . code = err . code ;
6262 this . errno = err . errno ;
6363 /* c8 ignore next */
6464 if ( ! this . code )
6565 this . code = 'ZLIB_ERROR' ;
6666 this . message = 'zlib: ' + err . message ;
67- Error . captureStackTrace ( this , this . constructor ) ;
67+ Error . captureStackTrace ( this , origin ?? this . constructor ) ;
6868 }
6969 get name ( ) {
7070 return 'ZlibError' ;
@@ -105,6 +105,10 @@ class ZlibBase extends minipass_1.Minipass {
105105 this . #finishFlushFlag = opts . finishFlush ?? 0 ;
106106 this . #fullFlushFlag = opts . fullFlushFlag ?? 0 ;
107107 /* c8 ignore stop */
108+ //@ts -ignore
109+ if ( typeof realZlib [ mode ] !== 'function' ) {
110+ throw new TypeError ( 'Compression method not supported: ' + mode ) ;
111+ }
108112 // this will throw if any options are invalid for the class selected
109113 try {
110114 // @types /node doesn't know that it exports the classes, but they're there
@@ -113,7 +117,7 @@ class ZlibBase extends minipass_1.Minipass {
113117 }
114118 catch ( er ) {
115119 // make sure that all errors get decorated properly
116- throw new ZlibError ( er ) ;
120+ throw new ZlibError ( er , this . constructor ) ;
117121 }
118122 this . #onError = err => {
119123 // no sense raising multiple errors, since we abort on the first one.
@@ -213,7 +217,7 @@ class ZlibBase extends minipass_1.Minipass {
213217 // or if we do, put Buffer.concat() back before we emit error
214218 // Error events call into user code, which may call Buffer.concat()
215219 passthroughBufferConcat ( false ) ;
216- this . #onError( new ZlibError ( err ) ) ;
220+ this . #onError( new ZlibError ( err , this . write ) ) ;
217221 }
218222 finally {
219223 if ( this . #handle) {
@@ -232,7 +236,7 @@ class ZlibBase extends minipass_1.Minipass {
232236 }
233237 }
234238 if ( this . #handle)
235- this . #handle. on ( 'error' , er => this . #onError( new ZlibError ( er ) ) ) ;
239+ this . #handle. on ( 'error' , er => this . #onError( new ZlibError ( er , this . write ) ) ) ;
236240 let writeReturn ;
237241 if ( result ) {
238242 if ( Array . isArray ( result ) && result . length > 0 ) {
@@ -376,7 +380,6 @@ class Brotli extends ZlibBase {
376380 super ( opts , mode ) ;
377381 }
378382}
379- exports . Brotli = Brotli ;
380383class BrotliCompress extends Brotli {
381384 constructor ( opts ) {
382385 super ( opts , 'BrotliCompress' ) ;
@@ -389,4 +392,25 @@ class BrotliDecompress extends Brotli {
389392 }
390393}
391394exports . BrotliDecompress = BrotliDecompress ;
395+ class Zstd extends ZlibBase {
396+ constructor ( opts , mode ) {
397+ opts = opts || { } ;
398+ opts . flush = opts . flush || constants_js_1 . constants . ZSTD_e_continue ;
399+ opts . finishFlush = opts . finishFlush || constants_js_1 . constants . ZSTD_e_end ;
400+ opts . fullFlushFlag = constants_js_1 . constants . ZSTD_e_flush ;
401+ super ( opts , mode ) ;
402+ }
403+ }
404+ class ZstdCompress extends Zstd {
405+ constructor ( opts ) {
406+ super ( opts , 'ZstdCompress' ) ;
407+ }
408+ }
409+ exports . ZstdCompress = ZstdCompress ;
410+ class ZstdDecompress extends Zstd {
411+ constructor ( opts ) {
412+ super ( opts , 'ZstdDecompress' ) ;
413+ }
414+ }
415+ exports . ZstdDecompress = ZstdDecompress ;
392416//# sourceMappingURL=index.js.map
0 commit comments