-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add streaming API for list objects v2
- Loading branch information
Showing
6 changed files
with
135 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
**/*.rs.bk | ||
Cargo.lock | ||
.idea | ||
*.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use super::Client; | ||
use crate::s3::{args::ListObjectsV2Args, error::Error, response::ListObjectsV2Response}; | ||
|
||
use futures_core::Stream; | ||
use futures_util::stream as futures_stream; | ||
|
||
impl Client { | ||
/// Executes | ||
/// [ListObjectsV2](https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html) | ||
/// S3 API repeatedly and returns a stream of results. Each result | ||
/// corresponds to the response of a single list request. This function | ||
/// manages pagination internally and stops when there are no more results. | ||
pub async fn list_objects_v2_stream( | ||
&self, | ||
args: ListObjectsV2Args, | ||
) -> impl Stream<Item = Result<ListObjectsV2Response, Error>> + Unpin { | ||
Box::pin(futures_stream::unfold( | ||
(self.clone(), args), | ||
move |(client, mut args)| async move { | ||
// args.continuation_token = continuation_token.clone(); | ||
let resp = client.list_objects_v2(&args).await; | ||
match resp { | ||
Ok(resp) => { | ||
if !resp.is_truncated { | ||
None | ||
} else { | ||
args.continuation_token = resp.next_continuation_token.clone(); | ||
Some((Ok(resp), (client, args))) | ||
} | ||
} | ||
Err(e) => Some((Err(e), (client, args))), | ||
} | ||
}, | ||
)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters