Struct Compress
struct Compress { ... }
Raw in-memory compression stream for blocks of data.
This type is the building block for the I/O streams in the rest of this
crate. It requires more management than the Read/Write API but is
maximally flexible in terms of accepting input from any source and being
able to produce output to any memory location.
It is recommended to use the I/O stream adaptors over this type as they're easier to use.
Implementations
impl Compress
fn new(level: Compression, zlib_header: bool) -> CompressCreates a new object ready for compressing data that it's given.
The
levelargument here indicates what level of compression is going to be performed, and thezlib_headerargument indicates whether the output data should have a zlib header or not.fn new_with_window_bits(level: Compression, zlib_header: bool, window_bits: u8) -> CompressCreates a new object ready for compressing data that it's given.
The
levelargument here indicates what level of compression is going to be performed, and thezlib_headerargument indicates whether the output data should have a zlib header or not. Thewindow_bitsparameter indicates the base-2 logarithm of the sliding window size and must be between 9 and 15.Panics
If
window_bitsdoes not fall into the range 9 ..= 15,new_with_window_bitswill panic.fn new_gzip(level: Compression, window_bits: u8) -> CompressCreates a new object ready for compressing data that it's given.
The
levelargument here indicates what level of compression is going to be performed.The Compress object produced by this constructor outputs gzip headers for the compressed data.
Panics
If
window_bitsdoes not fall into the range 9 ..= 15,new_with_window_bitswill panic.fn total_in(self: &Self) -> u64Returns the total number of input bytes which have been processed by this compression object.
fn total_out(self: &Self) -> u64Returns the total number of output bytes which have been produced by this compression object.
fn set_dictionary(self: &mut Self, dictionary: &[u8]) -> Result<u32, CompressError>Specifies the compression dictionary to use.
Returns the Adler-32 checksum of the dictionary.
fn reset(self: &mut Self)Quickly resets this compressor without having to reallocate anything.
This is equivalent to dropping this object and then creating a new one.
fn set_level(self: &mut Self, level: Compression) -> Result<(), CompressError>Dynamically updates the compression level.
This can be used to switch between compression levels for different kinds of data, or it can be used in conjunction with a call to reset to reuse the compressor.
This may return an error if there wasn't enough output space to complete the compression of the available input data before changing the compression level. Flushing the stream before calling this method ensures that the function will succeed on the first call.
fn compress(self: &mut Self, input: &[u8], output: &mut [u8], flush: FlushCompress) -> Result<Status, CompressError>Compresses the input data into the output, consuming only as much input as needed and writing as much output as possible.
The flush option can be any of the available
FlushCompressparameters.To learn how much data was consumed or how much output was produced, use the
total_inandtotal_outfunctions before/after this is called.fn compress_uninit(self: &mut Self, input: &[u8], output: &mut [MaybeUninit<u8>], flush: FlushCompress) -> Result<Status, CompressError>Similar to
Self::compressbut accepts uninitialized buffer.If you want to avoid the overhead of zero initializing the buffer and you don't want to use a
Vec, then please use this API.fn compress_vec(self: &mut Self, input: &[u8], output: &mut Vec<u8>, flush: FlushCompress) -> Result<Status, CompressError>Compresses the input data into the extra space of the output, consuming only as much input as needed and writing as much output as possible.
This function has the same semantics as
compress, except that the length ofvecis managed by this function. This will not reallocate the vector provided or attempt to grow it, so space for the output must be reserved in the output vector by the caller before calling this function.
impl Debug for Compress
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl Freeze for Compress
impl RefUnwindSafe for Compress
impl Send for Compress
impl Sync for Compress
impl Unpin for Compress
impl UnsafeUnpin for Compress
impl UnwindSafe for Compress
impl<T> Any for Compress
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Compress
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Compress
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> From for Compress
fn from(t: T) -> TReturns the argument unchanged.
impl<T, U> Into for Compress
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Compress
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Compress
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>