Skip to main content

AsyncRandomAccessReader

Struct AsyncRandomAccessReader 

Source
pub struct AsyncRandomAccessReader { /* private fields */ }
Expand description

An async random-access session bound to one opened object.

§Examples

This small example assumes each requested window fits the configured max_read_range_bytes; a larger single read_at request returns ResourceLimitExceeded. See the user guide for a fixture-backed helper that splits a larger sample across bounded reads.

use qubit_fs::{AsyncFileSystem, Path};
use qubit_fs::read::ReadOptions;

async fn sample(filesystem: &AsyncFileSystem, path: &Path) -> Result<Vec<u8>, qubit_fs::FsError> {
    let mut reader = filesystem.open_random_access_reader(path, ReadOptions::default()).await?;
    let mut bytes = [0; 16];
    let mut filled = 0;
    while filled < bytes.len() {
        match reader.read_at(filled as u64, &mut bytes[filled..]).await? {
            0 => break,
            count => filled += count,
        }
    }
    Ok(bytes[..filled].to_vec())
}

A short read is allowed. If a call returns Err or its future is dropped, the output may contain partial bytes; discard the incomplete sample. The cached length is not a content snapshot.

Implementations§

Source§

impl AsyncRandomAccessReader

Source

pub fn info(&self) -> &OpenedFileInfo

Returns the identity and metadata captured at open time.

Source

pub fn len(&self) -> u64

Returns the open-time readable upper bound.

This bound does not change if the object grows and does not make the object’s contents a snapshot.

Source

pub fn is_empty(&self) -> bool

Returns whether the open-time length is zero.

Source

pub async fn read_at( &mut self, offset: u64, output: &mut [u8], ) -> FsResult<usize>

Reads into caller storage at an explicit offset; cancellation does not change session identity.

§Parameters
  • offset: Byte offset from the beginning of the opened object.
  • output: Caller-owned destination buffer borrowed until the future completes or is dropped.
§Returns

Returns the number of bytes read. An empty output buffer returns zero without observing EOF. A non-overflowing request at or beyond the open-time length also returns zero without provider I/O. For a non-empty request within that bound, a provider result of zero indicates EOF observed by that request. A positive count may be shorter than the clipped request.

§Errors

Returns InvalidOptions for an overflowing offset range, ResourceLimitExceeded when the clipped request exceeds the provider limit, a provider error with path/provider/source context, or ProviderContractViolation when the provider over-reports bytes. The buffer may contain partial bytes after an error or cancellation and must be discarded. Provider-supplied path and provider context is preserved; missing fields are filled from this session. The operation is reported as Read.

Trait Implementations§

Source§

impl Debug for AsyncRandomAccessReader

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult

Formats the open-time information and length without exposing the provider session.

§Parameters
  • f: Destination for the debug representation.

Auto Trait Implementations§

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.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.