From 1061bf19b9dbf2cc5fac33710389baf67c775d8f Mon Sep 17 00:00:00 2001 From: ugo Date: Thu, 21 Apr 2022 16:54:52 +0800 Subject: [PATCH] Added ByteStream method to read from file chunk --- sdk/aws-smithy-http/src/byte_stream.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sdk/aws-smithy-http/src/byte_stream.rs b/sdk/aws-smithy-http/src/byte_stream.rs index d92937ba1f84..587b45f3815a 100644 --- a/sdk/aws-smithy-http/src/byte_stream.rs +++ b/sdk/aws-smithy-http/src/byte_stream.rs @@ -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 { + 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 {