@@ -842,45 +842,44 @@ const zstdDefaultOpts = {
842842 finishFlush : ZSTD_e_end ,
843843 fullFlush : ZSTD_e_flush ,
844844} ;
845- function Zstd ( opts , mode , initParamsArray , maxParam ) {
846- assert ( mode === ZSTD_COMPRESS || mode === ZSTD_DECOMPRESS ) ;
847-
848- initParamsArray . fill ( - 1 ) ;
849- if ( opts ?. params ) {
850- ObjectKeys ( opts . params ) . forEach ( ( origKey ) => {
851- const key = + origKey ;
852- if ( NumberIsNaN ( key ) || key < 0 || key > maxParam ||
853- ( initParamsArray [ key ] | 0 ) !== - 1 ) {
854- throw new ERR_ZSTD_INVALID_PARAM ( origKey ) ;
855- }
856-
857- const value = opts . params [ origKey ] ;
858- if ( typeof value !== 'number' && typeof value !== 'boolean' ) {
859- throw new ERR_INVALID_ARG_TYPE ( 'options.params[key]' ,
860- 'number' , opts . params [ origKey ] ) ;
861- }
862- initParamsArray [ key ] = value ;
863- } ) ;
864- }
845+ class Zstd extends ZlibBase {
846+ constructor ( opts , mode , initParamsArray , maxParam ) {
847+ assert ( mode === ZSTD_COMPRESS || mode === ZSTD_DECOMPRESS ) ;
848+
849+ initParamsArray . fill ( - 1 ) ;
850+ if ( opts ?. params ) {
851+ ObjectKeys ( opts . params ) . forEach ( ( origKey ) => {
852+ const key = + origKey ;
853+ if ( NumberIsNaN ( key ) || key < 0 || key > maxParam ||
854+ ( initParamsArray [ key ] | 0 ) !== - 1 ) {
855+ throw new ERR_ZSTD_INVALID_PARAM ( origKey ) ;
856+ }
857+
858+ const value = opts . params [ origKey ] ;
859+ if ( typeof value !== 'number' && typeof value !== 'boolean' ) {
860+ throw new ERR_INVALID_ARG_TYPE ( 'options.params[key]' ,
861+ 'number' , opts . params [ origKey ] ) ;
862+ }
863+ initParamsArray [ key ] = value ;
864+ } ) ;
865+ }
865866
866- const handle = mode === ZSTD_COMPRESS ?
867- new binding . ZstdCompress ( ) : new binding . ZstdDecompress ( ) ;
867+ const handle = mode === ZSTD_COMPRESS ?
868+ new binding . ZstdCompress ( ) : new binding . ZstdDecompress ( ) ;
868869
869- const pledgedSrcSize = opts ?. pledgedSrcSize ?? undefined ;
870+ const pledgedSrcSize = opts ?. pledgedSrcSize ?? undefined ;
870871
871- this . _writeState = new Uint32Array ( 2 ) ;
872- handle . init (
873- initParamsArray ,
874- pledgedSrcSize ,
875- this . _writeState ,
876- processCallback ,
877- ) ;
878-
879- ReflectApply ( ZlibBase , this , [ opts , mode , handle , zstdDefaultOpts ] ) ;
872+ const writeState = new Uint32Array ( 2 ) ;
873+ handle . init (
874+ initParamsArray ,
875+ pledgedSrcSize ,
876+ writeState ,
877+ processCallback ,
878+ ) ;
879+ super ( opts , mode , handle , zstdDefaultOpts ) ;
880+ this . _writeState = writeState ;
881+ }
880882}
881- ObjectSetPrototypeOf ( Zstd . prototype , ZlibBase . prototype ) ;
882- ObjectSetPrototypeOf ( Zstd , ZlibBase ) ;
883-
884883
885884const kMaxZstdCParam = MathMax ( ...ObjectKeys ( constants ) . map (
886885 ( key ) => ( key . startsWith ( 'ZSTD_c_' ) ?
@@ -890,16 +889,11 @@ const kMaxZstdCParam = MathMax(...ObjectKeys(constants).map(
890889
891890const zstdInitCParamsArray = new Uint32Array ( kMaxZstdCParam + 1 ) ;
892891
893- function ZstdCompress ( opts ) {
894- if ( ! ( this instanceof ZstdCompress ) )
895- return new ZstdCompress ( opts ) ;
896-
897- ReflectApply ( Zstd , this ,
898- [ opts , ZSTD_COMPRESS , zstdInitCParamsArray , kMaxZstdCParam ] ) ;
892+ class ZstdCompress extends Zstd {
893+ constructor ( opts ) {
894+ super ( opts , ZSTD_COMPRESS , zstdInitCParamsArray , kMaxZstdCParam ) ;
895+ }
899896}
900- ObjectSetPrototypeOf ( ZstdCompress . prototype , Zstd . prototype ) ;
901- ObjectSetPrototypeOf ( ZstdCompress , Zstd ) ;
902-
903897
904898const kMaxZstdDParam = MathMax ( ...ObjectKeys ( constants ) . map (
905899 ( key ) => ( key . startsWith ( 'ZSTD_d_' ) ?
@@ -909,16 +903,11 @@ const kMaxZstdDParam = MathMax(...ObjectKeys(constants).map(
909903
910904const zstdInitDParamsArray = new Uint32Array ( kMaxZstdDParam + 1 ) ;
911905
912- function ZstdDecompress ( opts ) {
913- if ( ! ( this instanceof ZstdDecompress ) )
914- return new ZstdDecompress ( opts ) ;
915-
916- ReflectApply ( Zstd , this ,
917- [ opts , ZSTD_DECOMPRESS , zstdInitDParamsArray , kMaxZstdDParam ] ) ;
906+ class ZstdDecompress extends Zstd {
907+ constructor ( opts ) {
908+ super ( opts , ZSTD_DECOMPRESS , zstdInitDParamsArray , kMaxZstdDParam ) ;
909+ }
918910}
919- ObjectSetPrototypeOf ( ZstdDecompress . prototype , Zstd . prototype ) ;
920- ObjectSetPrototypeOf ( ZstdDecompress , Zstd ) ;
921-
922911
923912function createProperty ( ctor ) {
924913 return {
0 commit comments