pub enum ByteSourceReader<R: BufRead> {
UncompressedMemory {
slice: Buffer<u8>,
offset: usize,
},
UncompressedStream(R),
Gzip(MultiGzDecoder<R>),
Zlib(ZlibDecoder<R>),
Zstd(Decoder<'static, R>),
}Expand description
A byte source that abstracts over in-memory buffers and streaming readers, with optional transparent decompression and buffering.
Implements BufRead, allowing uniform access regardless of whether
the underlying data is an in-memory slice, a raw stream, or a
compressed stream (gzip/zlib/zstd).
This is the generic successor to CompressedReader, which only
supports in-memory (Buffer<u8>) sources.
Variants§
UncompressedMemory
UncompressedStream(R)
Gzip(MultiGzDecoder<R>)
decompress only.Zlib(ZlibDecoder<R>)
decompress only.Zstd(Decoder<'static, R>)
decompress only.Implementations§
Source§impl<R: BufRead> ByteSourceReader<R>
impl<R: BufRead> ByteSourceReader<R>
pub fn try_new( reader: R, compression: Option<SupportedCompression>, ) -> PolarsResult<Self>
pub fn is_compressed(&self) -> bool
pub fn compression(&self) -> Option<SupportedCompression>
pub const fn initial_read_size() -> usize
pub const fn ideal_read_size() -> usize
Sourcepub fn read_next_slice(
&mut self,
prev_leftover: &Buffer<u8>,
read_size: usize,
uncompressed_size_hint: Option<usize>,
) -> Result<(Buffer<u8>, usize)>
pub fn read_next_slice( &mut self, prev_leftover: &Buffer<u8>, read_size: usize, uncompressed_size_hint: Option<usize>, ) -> Result<(Buffer<u8>, usize)>
Reads exactly read_size bytes if possible from the internal readers and creates a new
[Buffer] with the content concat(prev_leftover, new_bytes).
Returns the new slice and the number of bytes read, which will be 0 when eof is reached and this function is called again.
If the underlying reader is uncompressed the operation is a cheap zero-copy
[Buffer::sliced] operation.
By handling slice concatenation at this level we can implement zero-copy reading and make the interface easier to use.
It’s a logic bug if prev_leftover is neither empty nor the last slice returned by this
function.
Source§impl ByteSourceReader<ReaderSource>
impl ByteSourceReader<ReaderSource>
pub fn from_memory(slice: Buffer<u8>) -> PolarsResult<Self>
Auto Trait Implementations§
impl<R> Freeze for ByteSourceReader<R>where
R: Freeze,
impl<R> !RefUnwindSafe for ByteSourceReader<R>
impl<R> Send for ByteSourceReader<R>where
R: Send,
impl<R> Sync for ByteSourceReader<R>where
R: Sync,
impl<R> Unpin for ByteSourceReader<R>where
R: Unpin,
impl<R> UnsafeUnpin for ByteSourceReader<R>where
R: UnsafeUnpin,
impl<R> !UnwindSafe for ByteSourceReader<R>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more