| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a3ca7f3 commit 8e6c191
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -830,45 +830,44 @@ const zstdDefaultOpts = { | |||
| 830 | 830 | finishFlush: ZSTD_e_end, | |
| 831 | 831 | fullFlush: ZSTD_e_flush, | |
| 832 | 832 | }; | |
| 833 | - function Zstd(opts, mode, initParamsArray, maxParam) { | ||
| 834 | - assert(mode === ZSTD_COMPRESS || mode === ZSTD_DECOMPRESS); | ||
| 835 | - | ||
| 836 | - initParamsArray.fill(-1); | ||
| 837 | - if (opts?.params) { | ||
| 838 | - ObjectKeys(opts.params).forEach((origKey) => { | ||
| 839 | - const key = +origKey; | ||
| 840 | - if (NumberIsNaN(key) || key < 0 || key > maxParam || | ||
| 841 | - (initParamsArray[key] | 0) !== -1) { | ||
| 842 | - throw new ERR_ZSTD_INVALID_PARAM(origKey); | ||
| 843 | - } | ||
| 844 | - | ||
| 845 | - const value = opts.params[origKey]; | ||
| 846 | - if (typeof value !== 'number' && typeof value !== 'boolean') { | ||
| 847 | - throw new ERR_INVALID_ARG_TYPE('options.params[key]', | ||
| 848 | - 'number', opts.params[origKey]); | ||
| 849 | - } | ||
| 850 | - initParamsArray[key] = value; | ||
| 851 | - }); | ||
| 852 | - } | ||
| 853 | - | ||
| 854 | - const handle = mode === ZSTD_COMPRESS ? | ||
| 855 | - new binding.ZstdCompress() : new binding.ZstdDecompress(); | ||
| 833 | + class Zstd extends ZlibBase { | ||
| 834 | + constructor(opts, mode, initParamsArray, maxParam) { | ||
| 835 | + assert(mode === ZSTD_COMPRESS || mode === ZSTD_DECOMPRESS); | ||
| 836 | + | ||
| 837 | + initParamsArray.fill(-1); | ||
| 838 | + if (opts?.params) { | ||
| 839 | + ObjectKeys(opts.params).forEach((origKey) => { | ||
| 840 | + const key = +origKey; | ||
| 841 | + if (NumberIsNaN(key) || key < 0 || key > maxParam || | ||
| 842 | + (initParamsArray[key] | 0) !== -1) { | ||
| 843 | + throw new ERR_ZSTD_INVALID_PARAM(origKey); | ||
| 844 | + } | ||
| 845 | + | ||
| 846 | + const value = opts.params[origKey]; | ||
| 847 | + if (typeof value !== 'number' && typeof value !== 'boolean') { | ||
| 848 | + throw new ERR_INVALID_ARG_TYPE('options.params[key]', | ||
| 849 | + 'number', opts.params[origKey]); | ||
| 850 | + } | ||
| 851 | + initParamsArray[key] = value; | ||
| 852 | + }); | ||
| 853 | + } | ||
| 856 | 854 | ||
| 857 | - const pledgedSrcSize = opts?.pledgedSrcSize ?? undefined; | ||
| 855 | + const handle = mode === ZSTD_COMPRESS ? | ||
| 856 | + new binding.ZstdCompress() : new binding.ZstdDecompress(); | ||
| 858 | 857 | ||
| 859 | - this._writeState = new Uint32Array(2); | ||
| 860 | - handle.init( | ||
| 861 | - initParamsArray, | ||
| 862 | - pledgedSrcSize, | ||
| 863 | - this._writeState, | ||
| 864 | - processCallback, | ||
| 865 | - ); | ||
| 858 | + const pledgedSrcSize = opts?.pledgedSrcSize ?? undefined; | ||
| 866 | 859 | ||
| 867 | - ReflectApply(ZlibBase, this, [opts, mode, handle, zstdDefaultOpts]); | ||
| 860 | + const writeState = new Uint32Array(2); | ||
| 861 | + handle.init( | ||
| 862 | + initParamsArray, | ||
| 863 | + pledgedSrcSize, | ||
| 864 | + writeState, | ||
| 865 | + processCallback, | ||
| 866 | + ); | ||
| 867 | + super(opts, mode, handle, zstdDefaultOpts); | ||
| 868 | + this._writeState = writeState; | ||
| 869 | + } | ||
| 868 | 870 | } | |
| 869 | - ObjectSetPrototypeOf(Zstd.prototype, ZlibBase.prototype); | ||
| 870 | - ObjectSetPrototypeOf(Zstd, ZlibBase); | ||
| 871 | - | ||
| 872 | 871 | ||
| 873 | 872 | const kMaxZstdCParam = MathMax(...ObjectKeys(constants).map( | |
| 874 | 873 | (key) => (key.startsWith('ZSTD_c_') ? | |
@@ -878,16 +877,11 @@ const kMaxZstdCParam = MathMax(...ObjectKeys(constants).map( | |||
| 878 | 877 | ||
| 879 | 878 | const zstdInitCParamsArray = new Uint32Array(kMaxZstdCParam + 1); | |
| 880 | 879 | ||
| 881 | - function ZstdCompress(opts) { | ||
| 882 | - if (!(this instanceof ZstdCompress)) | ||
| 883 | - return new ZstdCompress(opts); | ||
| 884 | - | ||
| 885 | - ReflectApply(Zstd, this, | ||
| 886 | - [opts, ZSTD_COMPRESS, zstdInitCParamsArray, kMaxZstdCParam]); | ||
| 880 | + class ZstdCompress extends Zstd { | ||
| 881 | + constructor(opts) { | ||
| 882 | + super(opts, ZSTD_COMPRESS, zstdInitCParamsArray, kMaxZstdCParam); | ||
| 883 | + } | ||
| 887 | 884 | } | |
| 888 | - ObjectSetPrototypeOf(ZstdCompress.prototype, Zstd.prototype); | ||
| 889 | - ObjectSetPrototypeOf(ZstdCompress, Zstd); | ||
| 890 | - | ||
| 891 | 885 | ||
| 892 | 886 | const kMaxZstdDParam = MathMax(...ObjectKeys(constants).map( | |
| 893 | 887 | (key) => (key.startsWith('ZSTD_d_') ? | |
@@ -897,16 +891,11 @@ const kMaxZstdDParam = MathMax(...ObjectKeys(constants).map( | |||
| 897 | 891 | ||
| 898 | 892 | const zstdInitDParamsArray = new Uint32Array(kMaxZstdDParam + 1); | |
| 899 | 893 | ||
| 900 | - function ZstdDecompress(opts) { | ||
| 901 | - if (!(this instanceof ZstdDecompress)) | ||
| 902 | - return new ZstdDecompress(opts); | ||
| 903 | - | ||
| 904 | - ReflectApply(Zstd, this, | ||
| 905 | - [opts, ZSTD_DECOMPRESS, zstdInitDParamsArray, kMaxZstdDParam]); | ||
| 894 | + class ZstdDecompress extends Zstd { | ||
| 895 | + constructor(opts) { | ||
| 896 | + super(opts, ZSTD_DECOMPRESS, zstdInitDParamsArray, kMaxZstdDParam); | ||
| 897 | + } | ||
| 906 | 898 | } | |
| 907 | - ObjectSetPrototypeOf(ZstdDecompress.prototype, Zstd.prototype); | ||
| 908 | - ObjectSetPrototypeOf(ZstdDecompress, Zstd); | ||
| 909 | - | ||
| 910 | 899 | ||
| 911 | 900 | function createProperty(ctor) { | |
| 912 | 901 | return { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -40,7 +40,7 @@ const unzips = [ | |||
| 40 | 40 | zlib.Inflate(), | |
| 41 | 41 | zlib.InflateRaw(), | |
| 42 | 42 | zlib.BrotliDecompress(), | |
| 43 | - zlib.ZstdDecompress(), | ||
| 43 | + new zlib.ZstdDecompress(), | ||
| 44 | 44 | ]; | |
| 45 | 45 | ||
| 46 | 46 | nonStringInputs.forEach(common.mustCall((input) => { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,7 +36,7 @@ test('zlib should properly handle zero byte input', async () => { | |||
| 36 | 36 | ||
| 37 | 37 | for (const [Compressor, expected] of compressors) { | |
| 38 | 38 | const { promise, resolve, reject } = Promise.withResolvers(); | |
| 39 | - const gz = Compressor(); | ||
| 39 | + const gz = new Compressor(); | ||
| 40 | 40 | const emptyBuffer = Buffer.alloc(0); | |
| 41 | 41 | let received = 0; | |
| 42 | 42 | gz.on('data', function(c) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments