pub struct FsBuilder { /* private fields */ }
Expand description

Builder for creating ByteStreams from a file/path, with full control over advanced options.

Example usage:

use aws_smithy_http::byte_stream::{ByteStream, Length};
use std::path::Path;
struct GetObjectInput {
    body: ByteStream
}

async fn bytestream_from_file() -> GetObjectInput {
    let bytestream = ByteStream::read_from()
        .path("docs/some-large-file.csv")
        // Specify the size of the buffer used to read the file (in bytes, default is 4096)
        .buffer_size(32_784)
        // Specify the length of the file used (skips an additional call to retrieve the size)
        .length(Length::UpTo(123_456))
        .build()
        .await
        .expect("valid path");
    GetObjectInput { body: bytestream }
}

Implementations§

source§

impl FsBuilder

source

pub fn new() -> Self

Create a new FsBuilder (using a default read buffer of 4096 bytes).

You must then call either file or path to specify what to read from.

source

pub fn path(self, path: impl AsRef<Path>) -> Self

Sets the path to read from.

NOTE: The resulting ByteStream (after calling build) will be retryable. The returned ByteStream will provide a size hint when used as an HTTP body. If the request fails, the read will begin again by reloading the file handle.

source

pub fn file(self, file: File) -> Self

Sets the file to read from.

NOTE: The resulting ByteStream (after calling build) will not be a retryable ByteStream. For a ByteStream that can be retried in the case of upstream failures, use FsBuilder::path.

source

pub fn length(self, length: Length) -> Self

Specify the length to read (in bytes).

By pre-specifying the length, this API skips an additional call to retrieve the size from file-system metadata.

When used in conjunction with offset, allows for reading a single “chunk” of a file.

source

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

Specify the size of the buffer used to read the file (in bytes).

Increasing the read buffer capacity to higher values than the default (4096 bytes) can result in a large reduction in CPU usage, at the cost of memory increase.

source

pub fn offset(self, offset: u64) -> Self

Specify the offset to start reading from (in bytes)

When used in conjunction with length, allows for reading a single “chunk” of a file.

source

pub async fn build(self) -> Result<ByteStream, Error>

Returns a ByteStream from this builder.

Trait Implementations§

source§

impl Default for FsBuilder

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere 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 Twhere U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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.
source§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more