Skip to content

Commit 7f01a9f

Browse files
authored
Merge pull request #128 from oyvindln/rust-backend
Rust backend miniz_oxide
2 parents dbf4568 + 3eea583 commit 7f01a9f

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ script:
1515
- cargo test --verbose --features tokio
1616
- cargo test --verbose --features 'tokio zlib'
1717
- cargo test --verbose --features zlib --no-default-features
18+
- cargo test --verbose --features rust_backend
19+
- cargo test --verbose --features rust_backend --no-default-features
1820
- cargo clean && cargo build
1921
- cargo doc --no-deps
2022
- cargo doc --no-deps --manifest-path=miniz-sys/Cargo.toml

Cargo.toml

+2
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 = { 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

+35-2
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,11 @@ mod imp {
138167
&mut self.inner
139168
}
140169
}
170+
}
141171

172+
#[cfg(not(feature = "zlib"))]
173+
mod crc_imp {
174+
use libc::{c_ulong, off_t};
142175
pub unsafe extern fn mz_crc32_combine(crc1: c_ulong,
143176
crc2: c_ulong,
144177
len2: off_t) -> c_ulong {

0 commit comments

Comments
 (0)