Struct aws_smithy_http::byte_stream::FsBuilder
source · [−]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;
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)
.file_size(123_456)
.build()
.await
.expect("valid path");
GetObjectInput { body: bytestream }
}
Implementations
sourceimpl FsBuilder
impl FsBuilder
sourcepub fn path(self, path: impl AsRef<Path>) -> Self
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.
sourcepub fn file(self, file: File) -> Self
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
.
sourcepub fn file_size(self, file_size: u64) -> Self
pub fn file_size(self, file_size: u64) -> Self
Specify the length of the file to read (in bytes).
By pre-specifying the length of the file, this API skips an additional call to retrieve the size from file-system metadata.
sourcepub fn buffer_size(self, buffer_size: usize) -> Self
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.
sourcepub async fn build(self) -> Result<ByteStream, Error>
pub async fn build(self) -> Result<ByteStream, Error>
Returns a ByteStream
from this builder.
NOTE: If both file
and path
have been called for this FsBuilder, build
will
read from the path specified by path
.
Panics
Panics if neither of the file
orpath
setters were called.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for FsBuilder
impl Send for FsBuilder
impl Sync for FsBuilder
impl Unpin for FsBuilder
impl UnwindSafe for FsBuilder
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more