Skip to main content

ByteSourceReader

Enum ByteSourceReader 

Source
pub enum ByteSourceReader<R>
where R: BufRead,
{ UncompressedMemory { slice: Buffer<u8>, offset: usize, }, UncompressedStream(R), Gzip(MultiGzDecoder<R>), Zlib(ZlibDecoder<R>), Zstd(Decoder<'static, R>), }
Available on crate feature polars-io only.
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

Fields

§slice: Buffer<u8>
§offset: usize
§

UncompressedStream(R)

§

Gzip(MultiGzDecoder<R>)

Available on crate feature decompress only.
§

Zlib(ZlibDecoder<R>)

Available on crate feature decompress only.
§

Zstd(Decoder<'static, R>)

Available on crate feature decompress only.

Implementations§

Source§

impl<R> ByteSourceReader<R>
where R: BufRead,

Source

pub fn try_new( reader: R, compression: Option<SupportedCompression>, ) -> Result<ByteSourceReader<R>, PolarsError>

Source

pub fn is_compressed(&self) -> bool

Source

pub fn compression(&self) -> Option<SupportedCompression>

Source

pub const fn initial_read_size() -> usize

Source

pub const fn ideal_read_size() -> usize

Source

pub fn read_next_slice( &mut self, prev_leftover: &Buffer<u8>, read_size: usize, uncompressed_size_hint: Option<usize>, ) -> Result<(Buffer<u8>, usize), Error>

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>

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> 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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> PlanCallbackArgs for T

§

impl<T> PlanCallbackOut for T