use std::fmt;
pub use cloudflare_zlib_sys::{Z_NO_COMPRESSION, Z_BEST_SPEED,
Z_BEST_COMPRESSION, Z_DEFAULT_COMPRESSION, Z_FILTERED,
Z_HUFFMAN_ONLY, Z_RLE, Z_FIXED, Z_DEFAULT_STRATEGY};
mod def;
pub use def::*;
mod inf;
pub use inf::*;
use std::os::raw::c_int;
#[inline]
#[must_use]
pub fn is_supported() -> bool {
#[cfg(target_arch = "x86_64")]
{
if is_x86_feature_detected!("sse4.2") && is_x86_feature_detected!("pclmulqdq") {
return true;
}
}
#[cfg(target_arch = "aarch64")]
{
if cfg!(feature = "arm-always") || cfg!(target_vendor = "apple") {
return true;
}
use std::arch::is_aarch64_feature_detected;
if is_aarch64_feature_detected!("neon") && is_aarch64_feature_detected!("crc") {
return true;
}
}
false
}
#[derive(Debug)]
pub enum ZError {
StreamEnd,
NeedDict,
Errno,
StreamError,
DataError,
MemError,
BufError,
VersionError,
DeflatedDataTooLarge(usize),
OtherError(c_int),
IncompatibleCPU,
}
impl ZError {
#[inline]
fn new(code: c_int) -> Self {
match code {
1 => ZError::StreamEnd,
2 => ZError::NeedDict,
-1 => ZError::Errno,
-2 => ZError::StreamError,
-3 => ZError::DataError,
-4 => ZError::MemError,
-5 => ZError::BufError,
-6 => ZError::VersionError,
other => ZError::OtherError(other),
}
}
}
impl fmt::Display for ZError {
#[cold]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
<Self as fmt::Debug>::fmt(self, f)
}
}
impl std::error::Error for ZError {
}