pub struct RandomAccessReader { /* private fields */ }Expand description
A random-access session bound to one opened object and its open-time length.
§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::{FileSystem, FsResult, Path};
use qubit_fs::read::{RandomAccessReader, ReadOptions};
fn sample(filesystem: &FileSystem, path: &Path) -> FsResult<Vec<u8>> {
let mut reader: RandomAccessReader = filesystem.open_random_access_reader(path, ReadOptions::default())?;
let mut bytes = [0; 16];
let mut filled = 0;
while filled < bytes.len() {
match reader.read_at(filled as u64, &mut bytes[filled..])? {
0 => break, // EOF; a short read is not an error.
count => filled += count,
}
}
Ok(bytes[..filled].to_vec())
}If read_at returns Err, the output may already contain partial bytes;
discard the incomplete sample. The open-time length is not a content
snapshot.
Implementations§
Source§impl RandomAccessReader
impl RandomAccessReader
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 fn read_at(&mut self, offset: u64, output: &mut [u8]) -> FsResult<usize>
pub fn read_at(&mut self, offset: u64, output: &mut [u8]) -> FsResult<usize>
Reads into caller storage at an explicit offset. Requests past len are
clipped.
§Parameters
offset: Byte offset from the beginning of the opened object.output: Caller-owned destination buffer.
§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 read error with path/provider/source context, or
ProviderContractViolation if the provider over-reports bytes. On an
error, the buffer may contain partial bytes and should be discarded.
Provider-supplied path and provider context is preserved; missing fields
are filled from this session. The operation is reported as Read.