pub struct DecompressDecoder { /* private fields */ }
Expand description

DecompressDecoder provides blocking decompress support for opendal: decode happen inside a blocking thread (user need to handle the decompress logic)

Note: please handle state carefully!

Examples

use futures::io::Cursor;
use opendal::io_util::DecompressDecoder;
use opendal::io_util::CompressAlgorithm;
use opendal::io_util::DecompressState;

let content = vec![0; 16 * 1024 * 1024];
let mut cr = DecompressDecoder::new(CompressAlgorithm::Gzip);
let mut result = vec![0; 16 * 1024 * 1024];
let mut amt = 0;
let mut cnt = 0;
loop {
    let (_, input) = content.split_at(amt);
    let (_, output) = result.split_at_mut(cnt);

    match cr.state() {
        DecompressState::Reading => {
            let read = cr.fill(&input);
            amt += read;
        }
        DecompressState::Decoding => {
            let written = cr.decode(output)?;
            cnt += written;
        }
        DecompressState::Flushing => {
            let written = cr.finish(output)?;
            cnt += written;
        }
        DecompressState::Done => {
            break;
        }
    }
}
}

Implementations

Create a new DecompressDecoder with given CompressAlgorithm

Get decompress state

Fetch more data from underlying reader.

Notes

For now, we will read all content into internal buffer. But in the future, we may change the implementation to only read part of input data.

So it’s required to check returning read size and advance the reader’s amt.

Decode data into output. Returns the data that has been written.

Finish a decompress press, flushing remaining data into output. Return the data that has been written.

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Applies the Compat adapter by value. Read more

Applies the Compat adapter by shared reference. Read more

Applies the Compat adapter by mutable reference. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

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

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more