Struct opendal::io_util::DecompressDecoder
source · [−]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
sourceimpl DecompressDecoder
impl DecompressDecoder
sourcepub fn new(algo: CompressAlgorithm) -> Self
pub fn new(algo: CompressAlgorithm) -> Self
Create a new DecompressDecoder with given CompressAlgorithm
sourcepub fn state(&self) -> DecompressState
pub fn state(&self) -> DecompressState
Get decompress state
sourcepub fn fill(&mut self, bs: &[u8]) -> usize
pub fn fill(&mut self, bs: &[u8]) -> usize
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.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for DecompressDecoder
impl Send for DecompressDecoder
impl Sync for DecompressDecoder
impl Unpin for DecompressDecoder
impl UnwindSafe for DecompressDecoder
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for Twhere
V: MultiLane<T>,
impl<V, T> VZip<V> for Twhere
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more