pub struct FsBuilder { /* private fields */ }
rt-tokio
only.Expand description
Builder for creating ByteStreams
from a file/path, with full control over advanced options.
use aws_smithy_types::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
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 length(self, length: Length) -> Self
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.
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 fn offset(self, offset: u64) -> Self
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.
Sourcepub async fn build(self) -> Result<ByteStream, Error>
pub async fn build(self) -> Result<ByteStream, Error>
Returns a ByteStream
from this builder.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for FsBuilder
impl !RefUnwindSafe for FsBuilder
impl Send for FsBuilder
impl Sync for FsBuilder
impl Unpin for FsBuilder
impl UnwindSafe for FsBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more