diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2023-08-11 17:12:35 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-11 11:42:35 +0000 |
commit | 2f00b0add476bb151bc3a713da165296906cfc2a (patch) | |
tree | ba43cae2dd787b8e0f0aae102210ecfb65aa2f90 /ext/node/polyfills/_zlib.mjs | |
parent | 65db8814c31464f2bc2a04dd5ffbaa71361c9f80 (diff) |
fix(ext/node): support dictionary option in zlib init (#20035)
Fixes https://github.com/denoland/deno/issues/19540
Diffstat (limited to 'ext/node/polyfills/_zlib.mjs')
-rw-r--r-- | ext/node/polyfills/_zlib.mjs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/ext/node/polyfills/_zlib.mjs b/ext/node/polyfills/_zlib.mjs index f73365800..a66ab6d04 100644 --- a/ext/node/polyfills/_zlib.mjs +++ b/ext/node/polyfills/_zlib.mjs @@ -11,6 +11,10 @@ import util from "node:util"; import { ok as assert } from "node:assert"; import { zlib as zlibConstants } from "ext:deno_node/internal_binding/constants.ts"; import { nextTick } from "ext:deno_node/_next_tick.ts"; +import { + isAnyArrayBuffer, + isArrayBufferView, +} from "ext:deno_node/internal/util/types.ts"; var kRangeErrorMessage = "Cannot create final Buffer. It would be larger " + "than 0x" + kMaxLength.toString(16) + " bytes"; @@ -321,9 +325,12 @@ function Zlib(opts, mode) { } } - if (opts.dictionary) { - if (!Buffer.isBuffer(opts.dictionary)) { - throw new Error("Invalid dictionary: it should be a Buffer instance"); + let dictionary = opts.dictionary; + if (dictionary !== undefined && !isArrayBufferView(dictionary)) { + if (isAnyArrayBuffer(dictionary)) { + dictionary = Buffer.from(dictionary); + } else { + throw new TypeError("Invalid dictionary"); } } @@ -354,7 +361,7 @@ function Zlib(opts, mode) { level, opts.memLevel || zlibConstants.Z_DEFAULT_MEMLEVEL, strategy, - opts.dictionary, + dictionary, ); this._buffer = Buffer.allocUnsafe(this._chunkSize); |