Skip to content

Rust backend miniz_oxide #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ script:
- cargo test --verbose --features tokio
- cargo test --verbose --features 'tokio zlib'
- cargo test --verbose --features zlib --no-default-features
- cargo test --verbose --features rust_backend
- cargo test --verbose --features rust_backend --no-default-features
- cargo clean && cargo build
- cargo doc --no-deps
- cargo doc --no-deps --manifest-path=miniz-sys/Cargo.toml
Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ miniz-sys = { path = "miniz-sys", version = "0.1.7", optional = true }
libz-sys = { version = "1.0", optional = true }
tokio-io = { version = "0.1", optional = true }
futures = { version = "0.1", optional = true }
miniz_oxide_c_api = { version = "0.1", optional = true}

[dev-dependencies]
rand = "0.3"
Expand All @@ -33,6 +34,7 @@ tokio-core = "0.1"
[features]
default = ["miniz-sys"]
zlib = ["libz-sys"]
rust_backend = ["miniz_oxide_c_api"]
tokio = ["tokio-io", "futures"]

[badges]
Expand Down
37 changes: 35 additions & 2 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,43 @@ mod imp {
}
}

#[cfg(not(feature = "zlib"))]
#[cfg(all(not(feature = "zlib"), feature = "rust_backend"))]
mod imp {
extern crate miniz_oxide_c_api;
use std::ops::{Deref, DerefMut};

pub use ffi::crc_imp::*;
pub use self::miniz_oxide_c_api::*;
pub use self::miniz_oxide_c_api::lib_oxide::*;

#[derive(Debug, Default)]
pub struct StreamWrapper {
inner: mz_stream,
}

impl Deref for StreamWrapper {
type Target = mz_stream;

fn deref(&self) -> &Self::Target {
&self.inner
}
}

impl DerefMut for StreamWrapper {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
}
}
}

#[cfg(all(not(feature = "zlib"), not(feature = "rust_backend")))]
mod imp {
extern crate miniz_sys;
use std::mem;
use std::ops::{Deref, DerefMut};

use libc::{c_ulong, off_t};
pub use self::miniz_sys::*;
pub use ffi::crc_imp::*;

pub struct StreamWrapper {
inner: mz_stream,
Expand Down Expand Up @@ -138,7 +167,11 @@ mod imp {
&mut self.inner
}
}
}

#[cfg(not(feature = "zlib"))]
mod crc_imp {
use libc::{c_ulong, off_t};
pub unsafe extern fn mz_crc32_combine(crc1: c_ulong,
crc2: c_ulong,
len2: off_t) -> c_ulong {
Expand Down