pub struct SourceReader { /* private fields */ }Expand description
Supplies bytes to the receiver as either a sequential or seekable stream.
Use Self::streaming for Read-only sources, Self::seekable for
Read + Seek sources, or Self::spooled (feature spool) to materialize
a source into temporary storage.
The selected reader kind determines whether IStream::Seek can succeed
and whether the stream size can be derived when not explicitly provided.
Implementations§
Source§impl SourceReader
impl SourceReader
Sourcepub fn streaming<R>(reader: R) -> Self
pub fn streaming<R>(reader: R) -> Self
Wraps a sequential Read source without materializing its contents.
The reader does not support seeking, and its length cannot be derived.
Supply a size using crate::VirtualFile::with_size
when the receiving application requires one.
Sourcepub fn seekable<R>(reader: R) -> Self
pub fn seekable<R>(reader: R) -> Self
Wraps a Read + Seek source that supports random access.
When a file size is not provided, the length can be derived by seeking to the end and restoring the original position. The underlying reader must support those operations reliably.
Sourcepub fn spooled<R>(reader: R) -> Result<Self>
pub fn spooled<R>(reader: R) -> Result<Self>
Copies the complete source into a temporary file and returns a seekable reader backed by that file.
Spooling is explicit and finishes before this method returns. It trades temporary disk usage and startup latency for seekability and a derivable size. The temporary file’s lifetime is managed with the returned reader.
Requires the spool feature.
§Errors
Returns an I/O error if creating, writing, seeking, or reading the temporary file or source fails.
Trait Implementations§
Source§impl Read for SourceReader
impl Read for SourceReader
Source§fn read(&mut self, buffer: &mut [u8]) -> Result<usize>
fn read(&mut self, buffer: &mut [u8]) -> Result<usize>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(
&mut self,
cursor: BorrowedCursor<'_, u8>,
) -> Result<(), Error>
fn read_buf_exact( &mut self, cursor: BorrowedCursor<'_, u8>, ) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R> ⓘ
fn chain<R>(self, next: R) -> Chain<Self, R> ⓘ
1.0.0 · Source§fn take(self, limit: u64) -> Take<Self> ⓘwhere
Self: Sized,
fn take(self, limit: u64) -> Take<Self> ⓘwhere
Self: Sized,
limit bytes from it. Read moreSource§fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
read_array)