1#![deny(missing_docs)]
22#![cfg_attr(feature = "doc-cfg", feature(doc_cfg))]
23
24pub use zstd_safe;
26
27pub mod bulk;
28pub mod dict;
29
30#[macro_use]
31pub mod stream;
32
33use std::io;
34
35pub use zstd_safe::CLEVEL_DEFAULT as DEFAULT_COMPRESSION_LEVEL;
37
38pub fn compression_level_range(
40) -> std::ops::RangeInclusive<zstd_safe::CompressionLevel> {
41 zstd_safe::min_c_level()..=zstd_safe::max_c_level()
42}
43
44#[doc(no_inline)]
45pub use crate::stream::{decode_all, encode_all, Decoder, Encoder};
46
47fn map_error_code(code: usize) -> io::Error {
49 let msg = zstd_safe::get_error_name(code);
50 io::Error::new(io::ErrorKind::Other, msg.to_string())
51}
52
53#[cfg(test)]
56fn test_cycle<F, G>(data: &[u8], f: F, g: G)
57where
58 F: Fn(&[u8]) -> Vec<u8>,
59 G: Fn(&[u8]) -> Vec<u8>,
60{
61 let mid = f(data);
62 let end = g(&mid);
63 assert_eq!(data, &end[..]);
64}
65
66#[cfg(test)]
67fn test_cycle_unwrap<F, G>(data: &[u8], f: F, g: G)
68where
69 F: Fn(&[u8]) -> io::Result<Vec<u8>>,
70 G: Fn(&[u8]) -> io::Result<Vec<u8>>,
71{
72 test_cycle(data, |data| f(data).unwrap(), |data| g(data).unwrap())
73}
74
75#[test]
76fn default_compression_level_in_range() {
77 assert!(compression_level_range().contains(&DEFAULT_COMPRESSION_LEVEL));
78}