#![allow(unexpected_cfgs)]
# | [`futures::io::AsyncBufRead`](futures_io::AsyncBufRead), [`futures::io::AsyncWrite`](futures_io::AsyncWrite)"
)]
#![cfg_attr(
not(feature = "futures-io"),
doc = "`futures-io` (*inactive*) | `futures::io::AsyncBufRead`, `futures::io::AsyncWrite`"
)]
# | [`tokio::io::AsyncBufRead`](::tokio::io::AsyncBufRead), [`tokio::io::AsyncWrite`](::tokio::io::AsyncWrite)"
)]
#![cfg_attr(
not(feature = "tokio"),
doc = "`tokio` (*inactive*) | `tokio::io::AsyncBufRead`, `tokio::io::AsyncWrite`"
)]
#, [`BrotliDecoder`](?search=BrotliDecoder)"
)]
#![cfg_attr(
not(feature = "brotli"),
doc = "`brotli` (*inactive*) | `BrotliEncoder`, `BrotliDecoder`"
)]
#, [`BzDecoder`](?search=BzDecoder)"
)]
#![cfg_attr(
not(feature = "bzip2"),
doc = "`bzip2` (*inactive*) | `BzEncoder`, `BzDecoder`"
)]
#, [`DeflateDecoder`](?search=DeflateDecoder)"
)]
#![cfg_attr(
not(feature = "deflate"),
doc = "`deflate` (*inactive*) | `DeflateEncoder`, `DeflateDecoder`"
)]
#, [`GzipDecoder`](?search=GzipDecoder)"
)]
#![cfg_attr(
not(feature = "gzip"),
doc = "`gzip` (*inactive*) | `GzipEncoder`, `GzipDecoder`"
)]
#, [`LzmaDecoder`](?search=LzmaDecoder)"
)]
#![cfg_attr(
not(feature = "lzma"),
doc = "`lzma` (*inactive*) | `LzmaEncoder`, `LzmaDecoder`"
)]
#, [`XzDecoder`](?search=XzDecoder)"
)]
#![cfg_attr(
not(feature = "xz"),
doc = "`xz` (*inactive*) | `XzEncoder`, `XzDecoder`"
)]
#, [`ZlibDecoder`](?search=ZlibDecoder)"
)]
#![cfg_attr(
not(feature = "zlib"),
doc = "`zlib` (*inactive*) | `ZlibEncoder`, `ZlibDecoder`"
)]
#, [`ZstdDecoder`](?search=ZstdDecoder)"
)]
#![cfg_attr(
not(feature = "zstd"),
doc = "`zstd` (*inactive*) | `ZstdEncoder`, `ZstdDecoder`"
)]
#"
)]
#![cfg_attr(
not(feature = "deflate64"),
doc = "`deflate64` (*inactive*) | (encoder not implemented), `Deflate64Decoder`"
)]
#![cfg_attr(docsrs, feature(doc_auto_cfg, doc_cfg))]
#![warn(
missing_docs,
rust_2018_idioms,
missing_copy_implementations,
missing_debug_implementations
)]
#![cfg_attr(not(all), allow(unused))]
#[cfg(any(feature = "bzip2", feature = "flate2", feature = "xz2"))]
use std::convert::TryInto;
#[macro_use]
mod macros;
mod codec;
#[cfg(feature = "futures-io")]
pub mod futures;
#[cfg(feature = "tokio")]
pub mod tokio;
mod unshared;
mod util;
#[cfg(feature = "brotli")]
pub mod brotli;
#[cfg(feature = "zstd")]
pub mod zstd;
#[non_exhaustive]
#[derive(Clone, Copy, Debug)]
pub enum Level {
Fastest,
Best,
Default,
Precise(i32),
}
impl Level {
#[cfg(feature = "brotli")]
fn into_brotli(
self,
mut params: ::brotli::enc::backward_references::BrotliEncoderParams,
) -> ::brotli::enc::backward_references::BrotliEncoderParams {
match self {
Self::Fastest => params.quality = 0,
Self::Best => params.quality = 11,
Self::Precise(quality) => params.quality = quality.clamp(0, 11),
Self::Default => (),
}
params
}
#[cfg(feature = "bzip2")]
fn into_bzip2(self) -> bzip2::Compression {
let fastest = bzip2::Compression::fast();
let best = bzip2::Compression::best();
match self {
Self::Fastest => fastest,
Self::Best => best,
Self::Precise(quality) => bzip2::Compression::new(
quality
.try_into()
.unwrap_or(0)
.clamp(fastest.level(), best.level()),
),
Self::Default => bzip2::Compression::default(),
}
}
#[cfg(feature = "flate2")]
fn into_flate2(self) -> flate2::Compression {
let fastest = flate2::Compression::fast();
let best = flate2::Compression::best();
match self {
Self::Fastest => fastest,
Self::Best => best,
Self::Precise(quality) => flate2::Compression::new(
quality
.try_into()
.unwrap_or(0)
.clamp(fastest.level(), best.level()),
),
Self::Default => flate2::Compression::default(),
}
}
#[cfg(feature = "zstd")]
fn into_zstd(self) -> i32 {
let (fastest, best) = libzstd::compression_level_range().into_inner();
match self {
Self::Fastest => fastest,
Self::Best => best,
Self::Precise(quality) => quality.clamp(fastest, best),
Self::Default => libzstd::DEFAULT_COMPRESSION_LEVEL,
}
}
#[cfg(feature = "xz2")]
fn into_xz2(self) -> u32 {
match self {
Self::Fastest => 0,
Self::Best => 9,
Self::Precise(quality) => quality.try_into().unwrap_or(0).min(9),
Self::Default => 5,
}
}
}