| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 72448a8 commit 44042c2
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1099,6 +1099,10 @@ added: | |||
| 1099 | 1099 | - v23.8.0 | |
| 1100 | 1100 | - v22.15.0 | |
| 1101 | 1101 | changes: | |
| 1102 | + - version: REPLACEME | ||
| 1103 | + pr-url: https://github.com/nodejs/node/pull/64599 | ||
| 1104 | + description: The `dictionary` option can be a `TypedArray`, `DataView`, or | ||
| 1105 | + `ArrayBuffer`. | ||
| 1102 | 1106 | - version: v26.5.0 | |
| 1103 | 1107 | pr-url: https://github.com/nodejs/node/pull/64023 | |
| 1104 | 1108 | description: The `rejectGarbageAfterEnd` option was added. | |
@@ -1115,8 +1119,8 @@ Each Zstd-based class takes an `options` object. All options are optional. | |||
| 1115 | 1119 | * `maxOutputLength` {integer} Limits output size when using | |
| 1116 | 1120 | [convenience methods][]. **Default:** [`buffer.kMaxLength`][] | |
| 1117 | 1121 | * `info` {boolean} If `true`, returns an object with `buffer` and `engine`. **Default:** `false` | |
| 1118 | - * `dictionary` {Buffer} Optional dictionary used to | ||
| 1119 | - improve compression efficiency when compressing or decompressing data that | ||
| 1122 | + * `dictionary` {Buffer|TypedArray|DataView|ArrayBuffer} Optional dictionary used | ||
| 1123 | + to improve compression efficiency when compressing or decompressing data that | ||
| 1120 | 1124 | shares common patterns with the dictionary. | |
| 1121 | 1125 | * `rejectGarbageAfterEnd` {boolean} If `true`, decompression fails when | |
| 1122 | 1126 | input remains after the first complete compressed stream. **Default:** `false` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,6 +33,7 @@ const { | |||
| 33 | 33 | ObjectSetPrototypeOf, | |
| 34 | 34 | Symbol, | |
| 35 | 35 | Uint32Array, | |
| 36 | + Uint8Array, | ||
| 36 | 37 | } = primordials; | |
| 37 | 38 | ||
| 38 | 39 | const { | |
@@ -926,6 +927,15 @@ class Zstd extends ZlibBase { | |||
| 926 | 927 | }); | |
| 927 | 928 | } | |
| 928 | 929 | ||
| 930 | + let dictionary = opts?.dictionary; | ||
| 931 | + if (dictionary !== undefined && !isArrayBufferView(dictionary)) { | ||
| 932 | + if (isAnyArrayBuffer(dictionary)) { | ||
| 933 | + dictionary = new Uint8Array(dictionary); | ||
| 934 | + } else { | ||
| 935 | + dictionary = undefined; | ||
| 936 | + } | ||
| 937 | + } | ||
| 938 | + | ||
| 929 | 939 | const handle = mode === ZSTD_COMPRESS ? | |
| 930 | 940 | new binding.ZstdCompress() : new binding.ZstdDecompress(); | |
| 931 | 941 | ||
@@ -938,7 +948,7 @@ class Zstd extends ZlibBase { | |||
| 938 | 948 | pledgedSrcSize, | |
| 939 | 949 | writeState, | |
| 940 | 950 | processCallback, | |
| 941 | - opts?.dictionary && isArrayBufferView(opts.dictionary) ? opts.dictionary : undefined, | ||
| 951 | + dictionary, | ||
| 942 | 952 | ); | |
| 943 | 953 | ||
| 944 | 954 | super(opts, mode, handle, zstdDefaultOpts); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,3 +24,19 @@ zlib.zstdCompress(input, { dictionary }, common.mustSucceed((compressed) => { | |||
| 24 | 24 | assert.strictEqual(decompressed.toString(), input.toString()); | |
| 25 | 25 | })); | |
| 26 | 26 | })); | |
| 27 | + | ||
| 28 | + const baseline = zlib.zstdCompressSync(input, { dictionary }).length; | ||
| 29 | + | ||
| 30 | + const arrayBuffer = dictionary.buffer.slice( | ||
| 31 | + dictionary.byteOffset, dictionary.byteOffset + dictionary.byteLength); | ||
| 32 | + const uint8 = new Uint8Array(arrayBuffer); | ||
| 33 | + const dataView = new DataView(arrayBuffer); | ||
| 34 | + | ||
| 35 | + for (const dict of [arrayBuffer, uint8, dataView]) { | ||
| 36 | + assert.strictEqual(zlib.zstdCompressSync(input, { dictionary: dict }).length, | ||
| 37 | + baseline); | ||
| 38 | + | ||
| 39 | + const compressed = zlib.zstdCompressSync(input, { dictionary: dict }); | ||
| 40 | + const decompressed = zlib.zstdDecompressSync(compressed, { dictionary: dict }); | ||
| 41 | + assert.strictEqual(decompressed.toString(), input.toString()); | ||
| 42 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments