#![deny(missing_docs)]
extern crate libc;
#[cfg(test)]
extern crate partial_io;
extern crate zstd_safe;
pub mod stream;
pub mod block;
pub mod dict;
#[cfg(feature = "tokio")]
#[macro_use]
extern crate tokio_io;
#[cfg(feature = "tokio")]
extern crate futures;
#[cfg(all(test, feature = "tokio"))]
extern crate quickcheck;
use std::io;
#[doc(no_inline)]
pub use stream::{decode_all, encode_all, Decoder, Encoder};
fn parse_code(code: libc::size_t) -> Result<usize, io::Error> {
if zstd_safe::is_error(code) == 0 {
Ok(code as usize)
} else {
let msg = zstd_safe::get_error_name(code);
let error = io::Error::new(io::ErrorKind::Other, msg.to_string());
Err(error)
}
}
#[cfg(test)]
fn test_cycle<F, G>(data: &[u8], f: F, g: G)
where
F: Fn(&[u8]) -> Vec<u8>,
G: Fn(&[u8]) -> Vec<u8>,
{
let mid = f(data);
let end = g(&mid);
assert_eq!(data, &end[..]);
}
#[cfg(test)]
fn test_cycle_unwrap<F, G>(data: &[u8], f: F, g: G)
where
F: Fn(&[u8]) -> io::Result<Vec<u8>>,
G: Fn(&[u8]) -> io::Result<Vec<u8>>,
{
test_cycle(data, |data| f(data).unwrap(), |data| g(data).unwrap())
}