Skip to content

Commit b6ce6e9

Browse files
committed
Use add feature and ffi code to use miniz_c_api as back-end
1 parent 2b75ebc commit b6ce6e9

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ miniz-sys = { path = "miniz-sys", version = "0.1.7", optional = true }
2424
libz-sys = { version = "1.0", optional = true }
2525
tokio-io = { version = "0.1", optional = true }
2626
futures = { version = "0.1", optional = true }
27+
miniz_oxide_c_api = { git = "https://github.com/Frommi/miniz_oxide.git", version = "0.1", optional = true}
2728

2829
[dev-dependencies]
2930
rand = "0.3"
@@ -33,6 +34,7 @@ tokio-core = "0.1"
3334
[features]
3435
default = ["miniz-sys"]
3536
zlib = ["libz-sys"]
37+
rust_backend = ["miniz_oxide_c_api"]
3638
tokio = ["tokio-io", "futures"]
3739

3840
[badges]

src/ffi.rs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,43 @@ mod imp {
9898
}
9999
}
100100

101-
#[cfg(not(feature = "zlib"))]
101+
#[cfg(all(not(feature = "zlib"), feature = "rust_backend"))]
102+
mod imp {
103+
extern crate miniz_oxide_c_api;
104+
use std::ops::{Deref, DerefMut};
105+
106+
pub use ffi::crc_imp::*;
107+
pub use self::miniz_oxide_c_api::*;
108+
pub use self::miniz_oxide_c_api::lib_oxide::*;
109+
110+
#[derive(Debug, Default)]
111+
pub struct StreamWrapper {
112+
inner: mz_stream,
113+
}
114+
115+
impl Deref for StreamWrapper {
116+
type Target = mz_stream;
117+
118+
fn deref(&self) -> &Self::Target {
119+
&self.inner
120+
}
121+
}
122+
123+
impl DerefMut for StreamWrapper {
124+
fn deref_mut(&mut self) -> &mut Self::Target {
125+
&mut self.inner
126+
}
127+
}
128+
}
129+
130+
#[cfg(all(not(feature = "zlib"), not(feature = "rust_backend")))]
102131
mod imp {
103132
extern crate miniz_sys;
104133
use std::mem;
105134
use std::ops::{Deref, DerefMut};
106135

107-
use libc::{c_ulong, off_t};
108136
pub use self::miniz_sys::*;
137+
pub use ffi::crc_imp::*;
109138

110139
pub struct StreamWrapper {
111140
inner: mz_stream,
@@ -138,7 +167,10 @@ mod imp {
138167
&mut self.inner
139168
}
140169
}
170+
}
141171

172+
mod crc_imp {
173+
use libc::{c_ulong, off_t};
142174
pub unsafe extern fn mz_crc32_combine(crc1: c_ulong,
143175
crc2: c_ulong,
144176
len2: off_t) -> c_ulong {

0 commit comments

Comments
 (0)