Stream

Struct Stream 

Source
pub struct Stream { /* private fields */ }
Expand description

Representation of an in-memory LZMA encoding or decoding stream.

Wraps the raw underlying lzma_stream type and provides the ability to create streams which can either decode or encode various LZMA-based formats.

Implementations§

Source§

impl Stream

Encoder-related functions

Source

pub fn new_easy_encoder(preset: u32, check: Check) -> Result<Stream, Error>

Initialize .xz stream encoder using a preset number

This is intended to be used by most for encoding data. The preset argument is a number 0-9 indicating the compression level to use, and normally 6 is a reasonable default.

The check argument is the integrity check to insert at the end of the stream. The default of Crc64 is typically appropriate.

Source

pub fn new_lzma_encoder(options: &LzmaOptions) -> Result<Stream, Error>

Initialize .lzma encoder (legacy file format)

The .lzma format is sometimes called the LZMA_Alone format, which is the reason for the name of this function. The .lzma format supports only the LZMA1 filter. There is no support for integrity checks like CRC32.

Use this function if and only if you need to create files readable by legacy LZMA tools such as LZMA Utils 4.32.x. Moving to the .xz format (the new_easy_encoder function) is strongly recommended.

The valid action values for Stream::process are Action::Run and Action::Finish. No flushing is supported, because the file format doesn’t support it.

Source

pub fn new_stream_encoder( filters: &Filters, check: Check, ) -> Result<Stream, Error>

Initialize .xz Stream encoder using a custom filter chain

This function is similar to new_easy_encoder but a custom filter chain is specified.

Source

pub fn new_raw_encoder(filters: &Filters) -> Result<Stream, Error>

Initialize an encoder stream using a custom filter chain.

Source§

impl Stream

Decoder-related functions

Source

pub fn new_auto_decoder(memlimit: u64, flags: u32) -> Result<Stream, Error>

Initialize a decoder which will choose a stream/lzma formats depending on the input stream.

Source

pub fn new_stream_decoder(memlimit: u64, flags: u32) -> Result<Stream, Error>

Initialize a .xz stream decoder.

The maximum memory usage can be specified along with flags such as TELL_ANY_CHECK, TELL_NO_CHECK, TELL_UNSUPPORTED_CHECK, IGNORE_CHECK, or CONCATENATED.

Source

pub fn new_lzma_decoder(memlimit: u64) -> Result<Stream, Error>

Initialize a .lzma stream decoder.

The maximum memory usage can also be specified.

Source

pub fn new_lzip_decoder(memlimit: u64, flags: u32) -> Result<Self, Error>

Initialize a .lz stream decoder.

Source

pub fn new_raw_decoder(filters: &Filters) -> Result<Stream, Error>

Initialize a decoder stream using a custom filter chain.

Source§

impl Stream

Generic functions

Source

pub fn process( &mut self, input: &[u8], output: &mut [u8], action: Action, ) -> Result<Status, Error>

Processes some data from input into an output buffer.

This will perform the appropriate encoding or decoding operation depending on the kind of underlying stream. See Action for the possible actions that can be taken.

After the first use of Action::SyncFlush, Action::FullFlush, Action::FullBarrier, or Action::Finish, the same Action must be used until this returns Status::StreamEnd. Not doing so will result in a Error::Program.

The amount of input must not be modified by the application until this returns Status::StreamEnd, otherwise Error::Program will be returned.

Source

pub fn process_uninit( &mut self, input: &[u8], output: &mut [MaybeUninit<u8>], action: Action, ) -> Result<Status, Error>

Same as Self::process but accepts uninitialized buffer.

To retrieve bytes written into the output, please call Self::total_out() before and after the call to Self::process_uninit and the diff of total_out would be the bytes written to the output.

Source

pub fn process_vec( &mut self, input: &[u8], output: &mut Vec<u8>, action: Action, ) -> Result<Status, Error>

Performs the same data as Stream::process, but places output data in a Vec.

This function will use the extra capacity of output as a destination for bytes to be placed. The length of output will automatically get updated after the operation has completed.

See Stream::process for the other arguments.

Source

pub fn total_in(&self) -> u64

Returns the total amount of input bytes consumed by this stream.

Source

pub fn total_out(&self) -> u64

Returns the total amount of bytes produced by this stream.

Source

pub fn memlimit(&self) -> u64

Get the current memory usage limit.

This is only supported if the underlying stream supports a memlimit.

Source

pub fn set_memlimit(&mut self, limit: u64) -> Result<(), Error>

Set the current memory usage limit.

This can return Error::MemLimit if the new limit is too small or Error::Program if this stream doesn’t take a memory limit.

Trait Implementations§

Source§

impl Drop for Stream

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for Stream

Source§

impl Sync for Stream

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.