Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ByteStream method to read from file chunk #517

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions sdk/aws-smithy-http/src/byte_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,18 @@ impl ByteStream {
));
Ok(ByteStream::new(body))
}

/// Create a ByteStream from a file specifying offset and length
#[cfg(feature = "rt-tokio")]
pub async fn from_path_chunk(path: &std::path::Path, offset: u64, sz: u64) -> Result<Self, Error> {
let mut file = tokio::fs::File::open(path).await.map_err(|err| Error(err.into()))?;
use tokio::io::AsyncSeekExt;
let _s = file.seek(std::io::SeekFrom::Start(offset)).await.map_err(|err| Error(err.into()))?;
let body = SdkBody::from_dyn(http_body::combinators::BoxBody::new(
bytestream_util::PathBody::from_file(file, sz),
));
Ok(ByteStream::new(body))
}
}

impl Default for ByteStream {
Expand Down