pub struct Zstd { /* private fields */ }Expand description
Zstandard (RFC 8878): Content-Encoding: zstd.
Compresses at level 3 unless told otherwise, one frame with the content size in its
header. Output is byte for byte PHP’s zstd_compress() (libzstd 1.5.7). Decompressing
reads the first frame, like zstd_uncompress().
use utopia_compression::{Algorithm, Zstd};
let zstd = Zstd::new();
let body = zstd.compress(b"This is a demo string")?;
assert_eq!(body.len(), 30);
assert_eq!(zstd.decompress(&body)?, b"This is a demo string");use Utopia\Compression\Algorithms\Zstd;
$zstd = new Zstd();
$body = $zstd->compress('This is a demo string');
echo strlen($body), "\n"; // 30
echo $zstd->decompress($body), "\n"; // This is a demo stringRequires the zstd feature. PHP: Utopia\Compression\Algorithms\Zstd.
Implementations§
Source§impl Zstd
impl Zstd
Sourcepub const fn with_level(level: i64) -> Self
pub const fn with_level(level: i64) -> Self
Zstandard at level, unchecked: zstd’s negative (fast) levels work, and a level above
22 makes Algorithm::compress fail with Error::Codec, as in PHP.
PHP: new Zstd($level).
Sourcepub fn set_level(&mut self, level: i64) -> Result<(), Error>
pub fn set_level(&mut self, level: i64) -> Result<(), Error>
Sets the level. Fails with Error::InvalidArgument outside 1 to 22.
PHP: setLevel($level).
Sourcepub const fn is_supported() -> bool
pub const fn is_supported() -> bool
Whether this build has Zstandard (the zstd feature).
PHP: Zstd::isSupported(), whether zstd_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 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 Zstd
impl Algorithm for Zstd
Source§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 Zstd
impl Eq for Zstd
impl StructuralPartialEq for Zstd
Auto Trait Implementations§
impl Forget for Zstd
impl Freeze for Zstd
impl Move for Zstd
impl RefUnwindSafe for Zstd
impl Send for Zstd
impl Sync for Zstd
impl Unpin for Zstd
impl UnsafeUnpin for Zstd
impl UnwindSafe for Zstd
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.