@@ -851,45 +851,44 @@ const zstdDefaultOpts = {
851851 finishFlush : ZSTD_e_end ,
852852 fullFlush : ZSTD_e_flush ,
853853} ;
854- function Zstd ( opts , mode , initParamsArray , maxParam ) {
855- assert ( mode === ZSTD_COMPRESS || mode === ZSTD_DECOMPRESS ) ;
856-
857- initParamsArray . fill ( - 1 ) ;
858- if ( opts ?. params ) {
859- ObjectKeys ( opts . params ) . forEach ( ( origKey ) => {
860- const key = + origKey ;
861- if ( NumberIsNaN ( key ) || key < 0 || key > maxParam ||
862- ( initParamsArray [ key ] | 0 ) !== - 1 ) {
863- throw new ERR_ZSTD_INVALID_PARAM ( origKey ) ;
864- }
865-
866- const value = opts . params [ origKey ] ;
867- if ( typeof value !== 'number' && typeof value !== 'boolean' ) {
868- throw new ERR_INVALID_ARG_TYPE ( 'options.params[key]' ,
869- 'number' , opts . params [ origKey ] ) ;
870- }
871- initParamsArray [ key ] = value ;
872- } ) ;
873- }
854+ class Zstd extends ZlibBase {
855+ constructor ( opts , mode , initParamsArray , maxParam ) {
856+ assert ( mode === ZSTD_COMPRESS || mode === ZSTD_DECOMPRESS ) ;
857+
858+ initParamsArray . fill ( - 1 ) ;
859+ if ( opts ?. params ) {
860+ ObjectKeys ( opts . params ) . forEach ( ( origKey ) => {
861+ const key = + origKey ;
862+ if ( NumberIsNaN ( key ) || key < 0 || key > maxParam ||
863+ ( initParamsArray [ key ] | 0 ) !== - 1 ) {
864+ throw new ERR_ZSTD_INVALID_PARAM ( origKey ) ;
865+ }
866+
867+ const value = opts . params [ origKey ] ;
868+ if ( typeof value !== 'number' && typeof value !== 'boolean' ) {
869+ throw new ERR_INVALID_ARG_TYPE ( 'options.params[key]' ,
870+ 'number' , opts . params [ origKey ] ) ;
871+ }
872+ initParamsArray [ key ] = value ;
873+ } ) ;
874+ }
874875
875- const handle = mode === ZSTD_COMPRESS ?
876- new binding . ZstdCompress ( ) : new binding . ZstdDecompress ( ) ;
876+ const handle = mode === ZSTD_COMPRESS ?
877+ new binding . ZstdCompress ( ) : new binding . ZstdDecompress ( ) ;
877878
878- const pledgedSrcSize = opts ?. pledgedSrcSize ?? undefined ;
879+ const pledgedSrcSize = opts ?. pledgedSrcSize ?? undefined ;
879880
880- this . _writeState = new Uint32Array ( 2 ) ;
881- handle . init (
882- initParamsArray ,
883- pledgedSrcSize ,
884- this . _writeState ,
885- processCallback ,
886- ) ;
887-
888- ReflectApply ( ZlibBase , this , [ opts , mode , handle , zstdDefaultOpts ] ) ;
881+ const writeState = new Uint32Array ( 2 ) ;
882+ handle . init (
883+ initParamsArray ,
884+ pledgedSrcSize ,
885+ writeState ,
886+ processCallback ,
887+ ) ;
888+ super ( opts , mode , handle , zstdDefaultOpts ) ;
889+ this . _writeState = writeState ;
890+ }
889891}
890- ObjectSetPrototypeOf ( Zstd . prototype , ZlibBase . prototype ) ;
891- ObjectSetPrototypeOf ( Zstd , ZlibBase ) ;
892-
893892
894893const kMaxZstdCParam = MathMax ( ...ObjectKeys ( constants ) . map (
895894 ( key ) => ( key . startsWith ( 'ZSTD_c_' ) ?
@@ -899,16 +898,11 @@ const kMaxZstdCParam = MathMax(...ObjectKeys(constants).map(
899898
900899const zstdInitCParamsArray = new Uint32Array ( kMaxZstdCParam + 1 ) ;
901900
902- function ZstdCompress ( opts ) {
903- if ( ! ( this instanceof ZstdCompress ) )
904- return new ZstdCompress ( opts ) ;
905-
906- ReflectApply ( Zstd , this ,
907- [ opts , ZSTD_COMPRESS , zstdInitCParamsArray , kMaxZstdCParam ] ) ;
901+ class ZstdCompress extends Zstd {
902+ constructor ( opts ) {
903+ super ( opts , ZSTD_COMPRESS , zstdInitCParamsArray , kMaxZstdCParam ) ;
904+ }
908905}
909- ObjectSetPrototypeOf ( ZstdCompress . prototype , Zstd . prototype ) ;
910- ObjectSetPrototypeOf ( ZstdCompress , Zstd ) ;
911-
912906
913907const kMaxZstdDParam = MathMax ( ...ObjectKeys ( constants ) . map (
914908 ( key ) => ( key . startsWith ( 'ZSTD_d_' ) ?
@@ -918,16 +912,11 @@ const kMaxZstdDParam = MathMax(...ObjectKeys(constants).map(
918912
919913const zstdInitDParamsArray = new Uint32Array ( kMaxZstdDParam + 1 ) ;
920914
921- function ZstdDecompress ( opts ) {
922- if ( ! ( this instanceof ZstdDecompress ) )
923- return new ZstdDecompress ( opts ) ;
924-
925- ReflectApply ( Zstd , this ,
926- [ opts , ZSTD_DECOMPRESS , zstdInitDParamsArray , kMaxZstdDParam ] ) ;
915+ class ZstdDecompress extends Zstd {
916+ constructor ( opts ) {
917+ super ( opts , ZSTD_DECOMPRESS , zstdInitDParamsArray , kMaxZstdDParam ) ;
918+ }
927919}
928- ObjectSetPrototypeOf ( ZstdDecompress . prototype , Zstd . prototype ) ;
929- ObjectSetPrototypeOf ( ZstdDecompress , Zstd ) ;
930-
931920
932921function createProperty ( ctor ) {
933922 return {
0 commit comments