pub struct Snappy;Expand description
Snappy raw format: the uncompressed length as a varint, then literals and copies.
The compressor is a port of C++ snappy 1.2.1’s level 1 (the library
PHP’s ext-snappy links), with its portable hash: output is byte for byte
snappy_compress(). The decompressor is as strict as snappy’s: any
malformed tag, out-of-range copy or length mismatch fails.
use utopia_compression::{Algorithm, Snappy};
let snappy = Snappy::new();
let body = snappy.compress(b"This is a demo string")?;
assert_eq!(body.len(), 23);
assert_eq!(snappy.decompress(&body)?, b"This is a demo string");use Utopia\Compression\Algorithms\Snappy;
$snappy = new Snappy();
$body = $snappy->compress('This is a demo string');
echo strlen($body), "\n"; // 23
echo $snappy->decompress($body), "\n"; // This is a demo stringPure Rust, always available. PHP: Utopia\Compression\Algorithms\Snappy.
Implementations§
Source§impl Snappy
impl Snappy
Sourcepub const fn is_supported() -> bool
pub const fn is_supported() -> bool
Always true: Snappy is pure Rust.
PHP: Snappy::isSupported(), whether snappy_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: into room for snappy’s
MaxCompressedLength(), as snappy_compress() allocates it.
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: the length the input starts with is
allocated, as snappy_uncompress() allocates it, and the input must decode to exactly
that.
Trait Implementations§
Source§impl Algorithm for Snappy
impl Algorithm for Snappy
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 Snappy
impl Eq for Snappy
impl StructuralPartialEq for Snappy
Auto Trait Implementations§
impl Forget for Snappy
impl Freeze for Snappy
impl Move for Snappy
impl RefUnwindSafe for Snappy
impl Send for Snappy
impl Sync for Snappy
impl Unpin for Snappy
impl UnsafeUnpin for Snappy
impl UnwindSafe for Snappy
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.