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

Update aws-sdk-s3 to 0.35 #43

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ exclude = [".github"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
aws-sdk-s3 = "0.29"
aws-smithy-http = "0.56"
aws-sdk-s3 = "0.35"
aws-smithy-types = { version = "0.57", features = ["http-body-0-4-x"] }
base64 = "0.13"
bytes = "1"
futures = "0.3"
Expand All @@ -25,7 +25,7 @@ pin-project = "1"

[dev-dependencies]
anyhow = "1"
aws-config = "0.56"
aws-config = "0.57"
rand = "0.8"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
uuid = { version = "1", features = ["v4"] }
4 changes: 2 additions & 2 deletions src/into_byte_stream.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use aws_sdk_s3::primitives::ByteStream;
use aws_smithy_http::body::{Error, SdkBody};
use aws_smithy_types::body::{Error, SdkBody};
use bytes::Bytes;
use http::header::HeaderMap;
use http_body::combinators::BoxBody;
Expand Down Expand Up @@ -35,7 +35,7 @@ pub fn into_byte_stream(body: Vec<Bytes>) -> ByteStream {

let body = Arc::<[_]>::from(Box::from(body));
ByteStream::new(SdkBody::retryable(move || {
SdkBody::from_dyn(BoxBody::new(B(body.clone(), 0)))
SdkBody::from_body_0_4(BoxBody::new(B(body.clone(), 0)))
}))
}

Expand Down
31 changes: 26 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ use aws_sdk_s3::operation::complete_multipart_upload::{
};
use aws_sdk_s3::operation::create_multipart_upload::CreateMultipartUploadError;
use aws_sdk_s3::operation::upload_part::UploadPartError;
use aws_sdk_s3::primitives::ByteStream;
use aws_sdk_s3::primitives::{ByteStream, ByteStreamError};
use aws_sdk_s3::types::{CompletedMultipartUpload, CompletedPart};
use aws_sdk_s3::Client;
use aws_smithy_http::body::SdkBody;
use futures::{TryFutureExt, TryStreamExt};
use aws_smithy_types::body::SdkBody;
use bytes::Bytes;
use futures::{Stream, TryFutureExt, TryStreamExt};
use std::num::NonZeroUsize;
use std::ops::RangeInclusive;
use std::pin::Pin;
use std::task::{Context, Poll};

// https://docs.aws.amazon.com/AmazonS3/latest/userguide/qfacts.html
pub const PART_SIZE: RangeInclusive<usize> = 5 << 20..=5 << 30;
Expand All @@ -26,6 +29,8 @@ pub struct MultipartUpload {
key: Option<String>,
}

pub(crate) struct WrappedByteStream(ByteStream);

pub type MultipartUploadOutput = CompleteMultipartUploadOutput;

impl MultipartUpload {
Expand Down Expand Up @@ -65,7 +70,7 @@ impl MultipartUpload {
concurrency_limit: Option<NonZeroUsize>,
) -> Result<MultipartUploadOutput, (E, Option<AbortMultipartUploadFluentBuilder>)>
where
E: From<aws_smithy_http::byte_stream::error::Error>
E: From<aws_smithy_types::byte_stream::error::Error>
+ From<SdkError<CreateMultipartUploadError, http::Response<SdkBody>>>
+ From<SdkError<UploadPartError, http::Response<SdkBody>>>
+ From<SdkError<CompleteMultipartUploadError, http::Response<SdkBody>>>,
Expand All @@ -88,7 +93,7 @@ impl MultipartUpload {
.set_upload_id(upload_id.clone())
};

let parts = split::split(self.body, part_size)
let parts = split::split(WrappedByteStream::new(self.body), part_size)
.map_ok(|part| {
self.client
.upload_part()
Expand Down Expand Up @@ -136,5 +141,21 @@ impl MultipartUpload {
}
}

impl WrappedByteStream {
fn new(stream: ByteStream) -> Self {
Self(stream)
}
}

impl Unpin for WrappedByteStream {}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually, implementing Unpin manually is bad idea since the compiler infers Unpin automatically.


impl Stream for WrappedByteStream {
type Item = Result<Bytes, ByteStreamError>;

fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
Pin::new(&mut self.0).poll_next(cx)
}
}

#[cfg(test)]
mod tests;
6 changes: 3 additions & 3 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use aws_config::default_provider::credentials;
use aws_sdk_s3::config::Region;
use aws_sdk_s3::primitives::ByteStream;
use aws_sdk_s3::{Client, Config};
use aws_smithy_http::body::{self, SdkBody};
use aws_smithy_types::body::{self, SdkBody};
use bytes::Bytes;
use http::header::HeaderMap;
use http_body::combinators::BoxBody;
Expand Down Expand Up @@ -161,8 +161,8 @@ async fn test_abort() {
];

let (_, abort) = MultipartUpload::new(&client)
.body(ByteStream::new(SdkBody::from_dyn(BoxBody::new(B(
body.into_iter()
.body(ByteStream::new(SdkBody::from_body_0_4(BoxBody::new(B(
body.into_iter(),
)))))
.bucket(&bucket)
.key(&key)
Expand Down