pub struct Brotli { /* private fields */ }Expand description
Brotli (RFC 7932): Content-Encoding: br.
Compresses at quality Brotli::DEFAULT_LEVEL (11) unless
Brotli::set_level says otherwise, with a 4 MiB window (lgwin 22).
Decompressing accepts what brotli_uncompress() accepts, including
trailing bytes after the stream.
use utopia_compression::{Algorithm, Brotli};
let mut brotli = Brotli::new();
brotli.set_level(4)?;
let body = brotli.compress(b"This is a demo string")?;
assert_eq!(brotli.decompress(&body)?, b"This is a demo string");
assert_eq!(brotli.content_encoding(), "br");use Utopia\Compression\Algorithms\Brotli;
$brotli = new Brotli();
$brotli->setLevel(4);
$body = $brotli->compress('This is a demo string');
echo $brotli->decompress($body), "\n"; // This is a demo string
echo $brotli->getContentEncoding(), "\n"; // brThe codec is C brotli 1.2.1, the library PHP’s ext-brotli links, called the way
brotli_compress() calls it: the output is PHP’s, byte for byte, at every quality.
Requires the brotli feature. PHP: Utopia\Compression\Algorithms\Brotli.
Implementations§
Source§impl Brotli
impl Brotli
Sourcepub const DEFAULT_LEVEL: u32 = 11
pub const DEFAULT_LEVEL: u32 = 11
The quality of a new instance. PHP: BROTLI_COMPRESS_LEVEL_DEFAULT.
Sourcepub fn set_level(&mut self, level: i64) -> Result<(), Error>
pub fn set_level(&mut self, level: i64) -> Result<(), Error>
Sets the quality. Fails with Error::InvalidArgument outside 0
to 11.
PHP: setLevel($level).
Sourcepub fn use_generic_mode(&mut self)
pub fn use_generic_mode(&mut self)
Tunes the encoding for any data (the default).
PHP: useGenericMode().
Sourcepub fn use_text_mode(&mut self)
pub fn use_text_mode(&mut self)
Meant to tune the encoding for UTF-8 text, but keeps generic mode, as PHP does.
PHP: useTextMode(), which sets BROTLI_GENERIC (a quirk kept for
identical output).
Sourcepub fn use_font_mode(&mut self)
pub fn use_font_mode(&mut self)
Meant to tune the encoding for WOFF 2.0 fonts, but keeps generic mode, as PHP does.
PHP: useFontMode(), which sets BROTLI_GENERIC (a quirk kept for
identical output).
Sourcepub const fn is_supported() -> bool
pub const fn is_supported() -> bool
Whether this build has Brotli (the brotli feature).
PHP: Brotli::isSupported(), whether brotli_compress() exists.
Sourcepub fn compress_into<S: Sink + ?Sized>(
&self,
data: &[u8],
out: &mut S,
) -> Result<(), Error>
pub fn compress_into<S: Sink + ?Sized>( &self, data: &[u8], out: &mut S, ) -> Result<(), Error>
Algorithm::compress, appended to out.
Sourcepub fn compress_with<S: Sink + ?Sized>(
data: &[u8],
level: i64,
mode: i64,
out: &mut S,
) -> Result<(), Error>
pub fn compress_with<S: Sink + ?Sized>( data: &[u8], level: i64, mode: i64, out: &mut S, ) -> Result<(), Error>
Compresses data into out at level and mode (BROTLI_GENERIC, BROTLI_TEXT or
BROTLI_FONT: 0, 1 or 2), unchecked, as brotli_compress($data, $level, $mode) takes
them: either out of range fails with Error::Codec and PHP’s warning.
PHP: compress() on a subclass that set $level or $mode itself.
Sourcepub fn decompress_into<S: Sink + ?Sized>(
&self,
data: &[u8],
out: &mut S,
) -> Result<(), Error>
pub fn decompress_into<S: Sink + ?Sized>( &self, data: &[u8], out: &mut S, ) -> Result<(), Error>
Algorithm::decompress, appended to out.
Trait Implementations§
Source§impl Algorithm for Brotli
impl Algorithm for Brotli
Source§fn content_encoding(&self) -> Cow<'_, str>
fn content_encoding(&self) -> Cow<'_, str>
Content-Encoding and
Accept-Encoding headers: by default the name in lower case (ASCII
only); br for Brotli. Read moreSource§fn decompress(&self, data: &[u8]) -> Result<Vec<u8>, Error>
fn decompress(&self, data: &[u8]) -> Result<Vec<u8>, Error>
data. Fails with Error::Codec when data is not a
valid stream of the algorithm. Read moreimpl Copy for Brotli
impl Eq for Brotli
impl StructuralPartialEq for Brotli
Auto Trait Implementations§
impl Forget for Brotli
impl Freeze for Brotli
impl Move for Brotli
impl RefUnwindSafe for Brotli
impl Send for Brotli
impl Sync for Brotli
impl Unpin for Brotli
impl UnsafeUnpin for Brotli
impl UnwindSafe for Brotli
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.