summaryrefslogtreecommitdiff
path: root/ext/node
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2023-08-11 17:12:35 +0530
committerGitHub <noreply@github.com>2023-08-11 11:42:35 +0000
commit2f00b0add476bb151bc3a713da165296906cfc2a (patch)
treeba43cae2dd787b8e0f0aae102210ecfb65aa2f90 /ext/node
parent65db8814c31464f2bc2a04dd5ffbaa71361c9f80 (diff)
fix(ext/node): support dictionary option in zlib init (#20035)
Fixes https://github.com/denoland/deno/issues/19540
Diffstat (limited to 'ext/node')
-rw-r--r--ext/node/ops/zlib/mod.rs8
-rw-r--r--ext/node/polyfills/_zlib.mjs15
-rw-r--r--ext/node/polyfills/_zlib_binding.mjs2
3 files changed, 18 insertions, 7 deletions
diff --git a/ext/node/ops/zlib/mod.rs b/ext/node/ops/zlib/mod.rs
index 3d58d16f9..2ddf6f2cd 100644
--- a/ext/node/ops/zlib/mod.rs
+++ b/ext/node/ops/zlib/mod.rs
@@ -344,7 +344,7 @@ pub fn op_zlib_init(
window_bits: i32,
mem_level: i32,
strategy: i32,
- dictionary: Option<&[u8]>,
+ dictionary: &[u8],
) -> Result<i32, AnyError> {
let resource = zlib(state, handle)?;
let mut zlib = resource.inner.borrow_mut();
@@ -373,7 +373,11 @@ pub fn op_zlib_init(
zlib.init_stream()?;
- zlib.dictionary = dictionary.map(|buf| buf.to_vec());
+ zlib.dictionary = if !dictionary.is_empty() {
+ Some(dictionary.to_vec())
+ } else {
+ None
+ };
Ok(zlib.err)
}
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);
diff --git a/ext/node/polyfills/_zlib_binding.mjs b/ext/node/polyfills/_zlib_binding.mjs
index a04e7fed7..0b155cfd5 100644
--- a/ext/node/polyfills/_zlib_binding.mjs
+++ b/ext/node/polyfills/_zlib_binding.mjs
@@ -149,7 +149,7 @@ class Zlib {
windowBits,
memLevel,
strategy,
- dictionary,
+ dictionary ?? new Uint8Array(0),
);
if (err != Z_OK) {