Skip to content

Commit

Permalink
Use miniz_oxide directly
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindln committed Aug 7, 2019
1 parent dfb1082 commit 344f58b
Show file tree
Hide file tree
Showing 3 changed files with 268 additions and 22 deletions.
7 changes: 2 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@ miniz-sys = { path = "miniz-sys", version = "0.1.11", optional = true }
libz-sys = { version = "1.0", optional = true }
tokio-io = { version = "0.1.11", optional = true }
futures = { version = "0.1.25", optional = true }
miniz_oxide_c_api = { version = "0.2", optional = true, features = ["no_c_export"]}
miniz_oxide = { version = "0.3.1", optional = true}
crc32fast = "1.1"

[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dependencies]
miniz_oxide_c_api = { version = "0.2", features = ["no_c_export"] }

[dev-dependencies]
rand = "0.6"
quickcheck = { version = "0.8", default-features = false }
Expand All @@ -42,7 +39,7 @@ futures = "0.1"
[features]
default = ["miniz-sys"]
zlib = ["libz-sys"]
rust_backend = ["miniz_oxide_c_api"]
rust_backend = ["miniz_oxide"]
tokio = ["tokio-io", "futures"]

[badges]
Expand Down
52 changes: 38 additions & 14 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,30 +101,54 @@ mod imp {
all(target_arch = "wasm32", not(target_os = "emscripten"))
))]
mod imp {
extern crate miniz_oxide_c_api;
use std::ops::{Deref, DerefMut};
extern crate miniz_oxide;

pub use self::miniz_oxide_c_api::lib_oxide::*;
pub use self::miniz_oxide_c_api::*;
pub use self::miniz_oxide::inflate::stream::InflateState;
pub use self::miniz_oxide::*;

#[derive(Debug, Default)]
pub struct StreamWrapper {
inner: mz_stream,
pub const MZ_NO_FLUSH: isize = MZFlush::None as isize;
pub const MZ_PARTIAL_FLUSH: isize = MZFlush::Partial as isize;
pub const MZ_SYNC_FLUSH: isize = MZFlush::Sync as isize;
pub const MZ_FULL_FLUSH: isize = MZFlush::Full as isize;
pub const MZ_FINISH: isize = MZFlush::Finish as isize;

pub enum StreamWrapper {
Deflate(Box<deflate::core::CompressorOxide>),
Inflate(Box<InflateState>),
None,
}

impl Deref for StreamWrapper {
type Target = mz_stream;
impl StreamWrapper {
pub fn compressor(&mut self) -> &mut deflate::core::CompressorOxide {
match self {
StreamWrapper::Deflate(state) => state.as_mut(),
_ => panic!("Tried to compress with a decompressor!"),
}
}

fn deref(&self) -> &Self::Target {
&self.inner
pub fn decompressor(&mut self) -> &mut InflateState {
match self {
StreamWrapper::Inflate(state) => state.as_mut(),
_ => panic!("Tried to decompress with a compressor!"),
}
}
}

impl DerefMut for StreamWrapper {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
impl ::std::fmt::Debug for StreamWrapper {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> {
write!(f, "StreamWrapper")
}
}

impl Default for StreamWrapper {
fn default() -> Self {
StreamWrapper::None
}
}

/// Dummy
#[allow(non_camel_case_types)]
pub struct mz_stream {}
}

#[cfg(all(
Expand Down
Loading

0 comments on commit 344f58b

Please sign in to comment.