diff options
author | Matt Mastracci <matthew@mastracci.com> | 2023-11-11 07:20:12 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-11 07:20:12 -0700 |
commit | 56e76242f3d7082e412bc698ebc737d24910cb60 (patch) | |
tree | 1b7fc048e1a873b5b6d05870cd3485811966f671 /ext | |
parent | 0c1ab2c7f7a6ebf7856df71dbd790d0d731f1b86 (diff) |
chore(ext/node): use libz-sys w/`zlib-ng` feature in node (#21158)
We only want one zlib dependency.
Zlib dependencies are reorganized so they use a hidden
`__vendored_zlib_ng` flag in cli that enables zlib-ng for both libz-sys
(used by ext/node) and flate2 (used by deno_web).
Diffstat (limited to 'ext')
-rw-r--r-- | ext/node/Cargo.toml | 2 | ||||
-rw-r--r-- | ext/node/lib.rs | 2 | ||||
-rw-r--r-- | ext/node/ops/zlib/mod.rs | 3 | ||||
-rw-r--r-- | ext/node/ops/zlib/mode.rs | 16 | ||||
-rw-r--r-- | ext/node/ops/zlib/stream.rs | 51 |
5 files changed, 36 insertions, 38 deletions
diff --git a/ext/node/Cargo.toml b/ext/node/Cargo.toml index 49f5c846e..2d227394a 100644 --- a/ext/node/Cargo.toml +++ b/ext/node/Cargo.toml @@ -41,7 +41,7 @@ indexmap.workspace = true k256 = "0.13.1" lazy-regex.workspace = true libc.workspace = true -libz-sys = { version = "1.1.8", features = ["static"] } +libz-sys.workspace = true md-5 = "0.10.5" md4 = "0.10.2" num-bigint.workspace = true diff --git a/ext/node/lib.rs b/ext/node/lib.rs index d38f10f61..96c9aff63 100644 --- a/ext/node/lib.rs +++ b/ext/node/lib.rs @@ -18,6 +18,8 @@ use deno_fs::sync::MaybeSend; use deno_fs::sync::MaybeSync; use once_cell::sync::Lazy; +extern crate libz_sys as zlib; + pub mod analyze; pub mod errors; mod global; diff --git a/ext/node/ops/zlib/mod.rs b/ext/node/ops/zlib/mod.rs index d14b4342f..cf004219a 100644 --- a/ext/node/ops/zlib/mod.rs +++ b/ext/node/ops/zlib/mod.rs @@ -1,15 +1,14 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. - use deno_core::error::bad_resource_id; use deno_core::error::type_error; use deno_core::error::AnyError; use deno_core::op2; use deno_core::OpState; -use libz_sys::*; use std::borrow::Cow; use std::cell::RefCell; use std::future::Future; use std::rc::Rc; +use zlib::*; mod alloc; pub mod brotli; diff --git a/ext/node/ops/zlib/mode.rs b/ext/node/ops/zlib/mode.rs index ef89805ba..da12385e7 100644 --- a/ext/node/ops/zlib/mode.rs +++ b/ext/node/ops/zlib/mode.rs @@ -1,7 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -use libz_sys as sys; - #[derive(Debug)] pub enum Error { BadArgument, @@ -60,12 +58,12 @@ repr_i32! { #[derive(Clone, Copy, Debug, PartialEq, Default)] pub enum Flush { #[default] - None = sys::Z_NO_FLUSH, - Partial = sys::Z_PARTIAL_FLUSH, - Sync = sys::Z_SYNC_FLUSH, - Full = sys::Z_FULL_FLUSH, - Finish = sys::Z_FINISH, - Block = sys::Z_BLOCK, - Trees = sys::Z_TREES, + None = zlib::Z_NO_FLUSH, + Partial = zlib::Z_PARTIAL_FLUSH, + Sync = zlib::Z_SYNC_FLUSH, + Full = zlib::Z_FULL_FLUSH, + Finish = zlib::Z_FINISH, + Block = zlib::Z_BLOCK, + Trees = zlib::Z_TREES, } } diff --git a/ext/node/ops/zlib/stream.rs b/ext/node/ops/zlib/stream.rs index 90cd58ed3..e61c47c1c 100644 --- a/ext/node/ops/zlib/stream.rs +++ b/ext/node/ops/zlib/stream.rs @@ -2,19 +2,18 @@ use super::mode::Flush; use super::mode::Mode; -use libz_sys as sys; use std::ffi::c_int; use std::ops::Deref; use std::ops::DerefMut; pub struct StreamWrapper { - pub strm: sys::z_stream, + pub strm: zlib::z_stream, } impl Default for StreamWrapper { fn default() -> Self { Self { - strm: sys::z_stream { + strm: zlib::z_stream { next_in: std::ptr::null_mut(), avail_in: 0, total_in: 0, @@ -25,7 +24,7 @@ impl Default for StreamWrapper { state: std::ptr::null_mut(), zalloc: super::alloc::zalloc, zfree: super::alloc::zfree, - opaque: 0 as sys::voidpf, + opaque: 0 as zlib::voidpf, data_type: 0, adler: 0, reserved: 0, @@ -35,7 +34,7 @@ impl Default for StreamWrapper { } impl Deref for StreamWrapper { - type Target = sys::z_stream; + type Target = zlib::z_stream; fn deref(&self) -> &Self::Target { &self.strm @@ -50,14 +49,14 @@ impl DerefMut for StreamWrapper { impl StreamWrapper { pub fn reset(&mut self, mode: Mode) -> c_int { - // SAFETY: `self.strm` is an initialized `z_stream`. + // SAFETY: `self.strm` is an initialized `zlib::z_stream`. unsafe { match mode { Mode::Deflate | Mode::Gzip | Mode::DeflateRaw => { - sys::deflateReset(&mut self.strm) + zlib::deflateReset(&mut self.strm) } Mode::Inflate | Mode::Gunzip | Mode::InflateRaw | Mode::Unzip => { - sys::inflateReset(&mut self.strm) + zlib::inflateReset(&mut self.strm) } Mode::None => unreachable!(), } @@ -65,14 +64,14 @@ impl StreamWrapper { } pub fn end(&mut self, mode: Mode) { - // SAFETY: `self.strm` is an initialized `z_stream`. + // SAFETY: `self.strm` is an initialized `zlib::z_stream`. unsafe { match mode { Mode::Deflate | Mode::Gzip | Mode::DeflateRaw => { - sys::deflateEnd(&mut self.strm); + zlib::deflateEnd(&mut self.strm); } Mode::Inflate | Mode::Gunzip | Mode::InflateRaw | Mode::Unzip => { - sys::inflateEnd(&mut self.strm); + zlib::inflateEnd(&mut self.strm); } Mode::None => {} } @@ -86,47 +85,47 @@ impl StreamWrapper { mem_level: c_int, strategy: c_int, ) -> c_int { - // SAFETY: `self.strm` is an initialized `z_stream`. + // SAFETY: `self.strm` is an initialized `zlib::z_stream`. unsafe { - sys::deflateInit2_( + zlib::deflateInit2_( &mut self.strm, level, - sys::Z_DEFLATED, + zlib::Z_DEFLATED, window_bits, mem_level, strategy, - sys::zlibVersion(), - std::mem::size_of::<sys::z_stream>() as i32, + zlib::zlibVersion(), + std::mem::size_of::<zlib::z_stream>() as i32, ) } } pub fn inflate_init(&mut self, window_bits: c_int) -> c_int { - // SAFETY: `self.strm` is an initialized `z_stream`. + // SAFETY: `self.strm` is an initialized `zlib::z_stream`. unsafe { - sys::inflateInit2_( + zlib::inflateInit2_( &mut self.strm, window_bits, - sys::zlibVersion(), - std::mem::size_of::<sys::z_stream>() as i32, + zlib::zlibVersion(), + std::mem::size_of::<zlib::z_stream>() as i32, ) } } pub fn deflate(&mut self, flush: Flush) -> c_int { - // SAFETY: `self.strm` is an initialized `z_stream`. - unsafe { sys::deflate(&mut self.strm, flush as _) } + // SAFETY: `self.strm` is an initialized `zlib::z_stream`. + unsafe { zlib::deflate(&mut self.strm, flush as _) } } pub fn inflate(&mut self, flush: Flush) -> c_int { - // SAFETY: `self.strm` is an initialized `z_stream`. - unsafe { sys::inflate(&mut self.strm, flush as _) } + // SAFETY: `self.strm` is an initialized `zlib::z_stream`. + unsafe { zlib::inflate(&mut self.strm, flush as _) } } pub fn inflate_set_dictionary(&mut self, dictionary: &[u8]) -> c_int { - // SAFETY: `self.strm` is an initialized `z_stream`. + // SAFETY: `self.strm` is an initialized `zlib::z_stream`. unsafe { - sys::inflateSetDictionary( + zlib::inflateSetDictionary( &mut self.strm, dictionary.as_ptr() as *const _, dictionary.len() as _, |