Type Alias opendal::operator_futures::FutureReader

source ·
pub type FutureReader<F> = OperatorFuture<(OpRead, OpReader), Reader, F>;
Expand description

Future that generated by Operator::read_with or Operator::reader_with.

Users can add more options by public functions provided by this struct.

§Notes

(OpRead, ()) is a trick to make sure FutureReader is different from FutureRead

Aliased Type§

struct FutureReader<F> { /* private fields */ }

Implementations§

source§

impl<F: Future<Output = Result<Reader>>> FutureReader<F>

source

pub fn version(self, v: &str) -> Self

Set version for this reader.

This feature can be used to retrieve the data of a specified version of the given path.

If the version doesn’t exist, an error with kind ErrorKind::NotFound will be returned.


let mut r = op.reader_with("path/to/file").version(version).await?;
source

pub fn concurrent(self, concurrent: usize) -> Self

Set concurrent for the reader.

OpenDAL by default to write file without concurrent. This is not efficient for cases when users read large chunks of data. By setting concurrent, opendal will reading files concurrently on support storage services.

By setting concurrent, opendal will fetch chunks concurrently with the give chunk size.

let r = op.reader_with("path/to/file").concurrent(8).await?;
source

pub fn chunk(self, chunk_size: usize) -> Self

OpenDAL will use services’ preferred chunk size by default. Users can set chunk based on their own needs.

This following example will make opendal read data in 4MiB chunks:

let r = op
    .reader_with("path/to/file")
    .chunk(4 * 1024 * 1024)
    .await?;
source

pub fn gap(self, gap_size: usize) -> Self

Controls the optimization strategy for range reads in Reader::fetch.

When performing range reads, if the gap between two requested ranges is smaller than the configured gap size, OpenDAL will merge these ranges into a single read request and discard the unrequested data in between. This helps reduce the number of API calls to remote storage services.

This optimization is particularly useful when performing multiple small range reads that are close to each other, as it reduces the overhead of multiple network requests at the cost of transferring some additional data.

In this example, if two requested ranges are separated by less than 1MiB, they will be merged into a single read request:

let r = op
    .reader_with("path/to/file")
    .chunk(4 * 1024 * 1024)
    .gap(1024 * 1024)  // 1MiB gap
    .await?;
source

pub fn if_match(self, etag: &str) -> Self

Set if-match for this read request.

This feature can be used to check if the file’s ETag matches the given ETag.

If file exists and it’s etag doesn’t match, an error with kind ErrorKind::ConditionNotMatch will be returned.

use opendal::Operator;
let mut r = op.reader_with("path/to/file").if_match(etag).await?;
source

pub fn if_none_match(self, etag: &str) -> Self

Set if-none-match for this read request.

This feature can be used to check if the file’s ETag doesn’t match the given ETag.

If file exists and it’s etag match, an error with kind ErrorKind::ConditionNotMatch will be returned.

use opendal::Operator;
let mut r = op.reader_with("path/to/file").if_none_match(etag).await?;
source

pub fn if_modified_since(self, v: DateTime<Utc>) -> Self

Set if-modified-since for this read request.

This feature can be used to check if the file has been modified since the given timestamp.

If file exists and it hasn’t been modified since the specified time, an error with kind ErrorKind::ConditionNotMatch will be returned.

use opendal::Operator;
use chrono::DateTime;
use chrono::Utc;
let mut r = op.reader_with("path/to/file").if_modified_since(time).await?;
source

pub fn if_unmodified_since(self, v: DateTime<Utc>) -> Self

Set if-unmodified-since for this read request.

This feature can be used to check if the file hasn’t been modified since the given timestamp.

If file exists and it has been modified since the specified time, an error with kind ErrorKind::ConditionNotMatch will be returned.

use opendal::Operator;
use chrono::DateTime;
use chrono::Utc;
let mut r = op.reader_with("path/to/file").if_unmodified_since(time).await?;