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
impl AsyncRandomAccessReader
Sourcepub fn info(&self) -> &OpenedFileInfo
pub fn info(&self) -> &OpenedFileInfo
Returns the identity and metadata captured at open time.
Sourcepub fn len(&self) -> u64
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.
Sourcepub async fn read_at(
&mut self,
offset: u64,
output: &mut [u8],
) -> FsResult<usize>
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.