Skip to content

Commit 867ada4

Browse files
committed
initial design
1 parent 8ad8fd7 commit 867ada4

File tree

6 files changed

+353
-24
lines changed

6 files changed

+353
-24
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ libz-sys = { version = "1.1.20", optional = true, default-features = false }
2323
libz-ng-sys = { version = "1.1.16", optional = true }
2424
# this matches the default features, but we don't want to depend on the default features staying the same
2525
libz-rs-sys = { version = "0.5.1", optional = true, default-features = false, features = ["std", "rust-allocator"] }
26+
zlib-rs = { version = "0.5.1", optional = true, default-features = false, features = ["std", "rust-allocator"] }
2627
cloudflare-zlib-sys = { version = "0.3.6", optional = true }
2728
miniz_oxide = { version = "0.8.5", optional = true, default-features = false, features = ["with-alloc", "simd"] }
2829
crc32fast = "1.2.0"
@@ -43,7 +44,7 @@ zlib = ["any_zlib", "libz-sys"]
4344
zlib-default = ["any_zlib", "libz-sys/default"]
4445
zlib-ng-compat = ["zlib", "libz-sys/zlib-ng"]
4546
zlib-ng = ["any_zlib", "libz-ng-sys"]
46-
zlib-rs = ["any_zlib", "libz-rs-sys"]
47+
zlib-rs = ["any_impl", "dep:zlib-rs", "dep:libz-rs-sys"]
4748
cloudflare_zlib = ["any_zlib", "cloudflare-zlib-sys"]
4849
rust_backend = ["miniz_oxide", "any_impl"]
4950
miniz-sys = ["rust_backend"] # For backwards compatibility

src/ffi/c.rs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use super::*;
99
use crate::mem;
1010

1111
#[derive(Clone, Default)]
12-
pub struct ErrorMessage(Option<&'static str>);
12+
pub struct ErrorMessage(pub(crate) Option<&'static str>);
1313

1414
impl ErrorMessage {
1515
pub fn get(&self) -> Option<&str> {
@@ -55,34 +55,27 @@ impl Default for StreamWrapper {
5555
// zlib-ng
5656
feature = "zlib-ng",
5757
// libz-sys
58-
all(not(feature = "cloudflare_zlib"), not(feature = "zlib-ng"), not(feature = "zlib-rs"))
58+
all(not(feature = "cloudflare_zlib"), not(feature = "zlib-ng"))
5959
))]
6060
zalloc: allocator::zalloc,
6161
#[cfg(any(
6262
// zlib-ng
6363
feature = "zlib-ng",
6464
// libz-sys
65-
all(not(feature = "cloudflare_zlib"), not(feature = "zlib-ng"), not(feature = "zlib-rs"))
65+
all(not(feature = "cloudflare_zlib"), not(feature = "zlib-ng"))
6666
))]
6767
zfree: allocator::zfree,
6868

6969
#[cfg(
7070
// cloudflare-zlib
71-
all(feature = "cloudflare_zlib", not(feature = "zlib-rs"), not(feature = "zlib-ng")),
71+
all(feature = "cloudflare_zlib", not(feature = "zlib-ng")),
7272
)]
7373
zalloc: Some(allocator::zalloc),
7474
#[cfg(
7575
// cloudflare-zlib
76-
all(feature = "cloudflare_zlib", not(feature = "zlib-rs"), not(feature = "zlib-ng")),
76+
all(feature = "cloudflare_zlib", not(feature = "zlib-ng")),
7777
)]
7878
zfree: Some(allocator::zfree),
79-
80-
// for zlib-rs, it is most efficient to have it provide the allocator.
81-
// The libz-rs-sys dependency is configured to use the rust system allocator
82-
#[cfg(all(feature = "zlib-rs", not(feature = "zlib-ng")))]
83-
zalloc: None,
84-
#[cfg(all(feature = "zlib-rs", not(feature = "zlib-ng")))]
85-
zfree: None,
8679
})),
8780
}
8881
}
@@ -102,9 +95,9 @@ impl Drop for StreamWrapper {
10295
// zlib-ng
10396
feature = "zlib-ng",
10497
// cloudflare-zlib
105-
all(feature = "cloudflare_zlib", not(feature = "zlib-rs"), not(feature = "zlib-ng")),
98+
all(feature = "cloudflare_zlib", not(feature = "zlib-ng")),
10699
// libz-sys
107-
all(not(feature = "cloudflare_zlib"), not(feature = "zlib-ng"), not(feature = "zlib-rs")),
100+
all(not(feature = "cloudflare_zlib"), not(feature = "zlib-ng")),
108101
))]
109102
mod allocator {
110103
use super::*;
@@ -462,18 +455,18 @@ mod c_backend {
462455
#[cfg(feature = "zlib-ng")]
463456
use libz_ng_sys as libz;
464457

465-
#[cfg(all(feature = "zlib-rs", not(feature = "zlib-ng")))]
458+
#[cfg(not(feature = "zlib-ng"))]
466459
use libz_rs_sys as libz;
467460

468461
#[cfg(
469462
// cloudflare-zlib
470-
all(feature = "cloudflare_zlib", not(feature = "zlib-rs"), not(feature = "zlib-ng")),
463+
all(feature = "cloudflare_zlib", not(feature = "zlib-ng")),
471464
)]
472465
use cloudflare_zlib_sys as libz;
473466

474467
#[cfg(
475468
// libz-sys
476-
all(not(feature = "cloudflare_zlib"), not(feature = "zlib-ng"), not(feature = "zlib-rs")),
469+
all(not(feature = "cloudflare_zlib"), not(feature = "zlib-ng")),
477470
)]
478471
use libz_sys as libz;
479472

src/ffi/rust.rs renamed to src/ffi/miniz_oxide.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl From<FlushCompress> for MZFlush {
146146
impl DeflateBackend for Deflate {
147147
fn make(level: Compression, zlib_header: bool, _window_bits: u8) -> Self {
148148
// Check in case the integer value changes at some point.
149-
debug_assert!(level.level() <= 10);
149+
debug_assert!(level.level() <= 9);
150150

151151
let mut inner: Box<CompressorOxide> = Box::default();
152152
let format = format_from_bool(zlib_header);

src/ffi/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,15 @@ mod c;
6565
#[cfg(feature = "any_zlib")]
6666
pub use self::c::*;
6767

68+
#[cfg(all(feature = "zlib-rs"))]
69+
mod zlib_rs;
70+
#[cfg(all(feature = "zlib-rs"))]
71+
pub use self::zlib_rs::*;
72+
6873
#[cfg(all(not(feature = "any_zlib"), feature = "miniz_oxide"))]
69-
mod rust;
74+
mod miniz_oxide;
7075
#[cfg(all(not(feature = "any_zlib"), feature = "miniz_oxide"))]
71-
pub use self::rust::*;
76+
pub use self::miniz_oxide::*;
7277

7378
impl std::fmt::Debug for ErrorMessage {
7479
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {

0 commit comments

Comments
 (0)