Enum zstd_sys::ZSTD_frameType_e[][src]

#[repr(u32)]
pub enum ZSTD_frameType_e {
    ZSTD_frame,
    ZSTD_skippableFrame,
}
Expand description

Buffer-less streaming decompression (synchronous mode)

A ZSTD_DCtx object is required to track streaming operations. Use ZSTD_createDCtx() / ZSTD_freeDCtx() to manage it. A ZSTD_DCtx object can be re-used multiple times.

First typical operation is to retrieve frame parameters, using ZSTD_getFrameHeader(). Frame header is extracted from the beginning of compressed frame, so providing only the frame’s beginning is enough. Data fragment must be large enough to ensure successful decoding. ZSTD_frameHeaderSize_max bytes is guaranteed to always be large enough. @result : 0 : successful decoding, the ZSTD_frameHeader structure is correctly filled. >0 : srcSize is too small, please provide at least @result bytes on next attempt. errorCode, which can be tested using ZSTD_isError().

It fills a ZSTD_frameHeader structure with important information to correctly decode the frame, such as the dictionary ID, content size, or maximum back-reference distance (windowSize). Note that these values could be wrong, either because of data corruption, or because a 3rd party deliberately spoofs false information. As a consequence, check that values remain within valid application range. For example, do not allocate memory blindly, check that windowSize is within expectation. Each application can set its own limits, depending on local restrictions. For extended interoperability, it is recommended to support windowSize of at least 8 MB.

ZSTD_decompressContinue() needs previous data blocks during decompression, up to windowSize bytes. ZSTD_decompressContinue() is very sensitive to contiguity, if 2 blocks don’t follow each other, make sure that either the compressor breaks contiguity at the same place, or that previous contiguous segment is large enough to properly handle maximum back-reference distance. There are multiple ways to guarantee this condition.

The most memory efficient way is to use a round buffer of sufficient size. Sufficient size is determined by invoking ZSTD_decodingBufferSize_min(), which can @return an error code if required value is too large for current system (in 32-bits mode). In a round buffer methodology, ZSTD_decompressContinue() decompresses each block next to previous one, up to the moment there is not enough room left in the buffer to guarantee decoding another full block, which maximum size is provided in ZSTD_frameHeader structure, field blockSizeMax. At which point, decoding can resume from the beginning of the buffer. Note that already decoded data stored in the buffer should be flushed before being overwritten.

There are alternatives possible, for example using two or more buffers of size windowSize each, though they consume more memory.

Finally, if you control the compression process, you can also ignore all buffer size rules, as long as the encoder and decoder progress in “lock-step”, aka use exactly the same buffer sizes, break contiguity at the same place, etc.

Once buffers are setup, start decompression, with ZSTD_decompressBegin(). If decompression requires a dictionary, use ZSTD_decompressBegin_usingDict() or ZSTD_decompressBegin_usingDDict().

Then use ZSTD_nextSrcSizeToDecompress() and ZSTD_decompressContinue() alternatively. ZSTD_nextSrcSizeToDecompress() tells how many bytes to provide as ‘srcSize’ to ZSTD_decompressContinue(). ZSTD_decompressContinue() requires this exact amount of bytes, or it will fail.

@result of ZSTD_decompressContinue() is the number of bytes regenerated within ‘dst’ (necessarily <= dstCapacity). It can be zero : it just means ZSTD_decompressContinue() has decoded some metadata item. It can also be an error code, which can be tested with ZSTD_isError().

A frame is fully decoded when ZSTD_nextSrcSizeToDecompress() returns zero. Context can then be reset to start a new decompression.

Note : it’s possible to know if next input to present is a header or a block, using ZSTD_nextInputType(). This information is not required to properly decode a frame.

== Special case : skippable frames ==

Skippable frames allow integration of user-defined data into a flow of concatenated frames. Skippable frames will be ignored (skipped) by decompressor. The format of skippable frames is as follows : a) Skippable frame ID - 4 Bytes, Little endian format, any value from 0x184D2A50 to 0x184D2A5F b) Frame Size - 4 Bytes, Little endian format, unsigned 32-bits c) Frame Content - any content (User Data) of length equal to Frame Size For skippable frames ZSTD_getFrameHeader() returns zfhPtr->frameType==ZSTD_skippableFrame. For skippable frames ZSTD_decompressContinue() always returns 0 : it only skips the content.

Variants

ZSTD_frame
ZSTD_skippableFrame

Trait Implementations

impl Clone for ZSTD_frameType_e[src]

fn clone(&self) -> ZSTD_frameType_e[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for ZSTD_frameType_e[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl Hash for ZSTD_frameType_e[src]

fn hash<__H: Hasher>(&self, state: &mut __H)[src]

Feeds this value into the given Hasher. Read more

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

Feeds a slice of this type into the given Hasher. Read more

impl PartialEq<ZSTD_frameType_e> for ZSTD_frameType_e[src]

fn eq(&self, other: &ZSTD_frameType_e) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl Copy for ZSTD_frameType_e[src]

impl Eq for ZSTD_frameType_e[src]

impl StructuralEq for ZSTD_frameType_e[src]

impl StructuralPartialEq for ZSTD_frameType_e[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.