-
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
159 additions
and
27 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,38 @@ | ||
use crate::s3::{ | ||
args::ListObjectsV2Args, client::Client, error::Error, response::ListObjectsV2Response, | ||
}; | ||
|
||
use futures_core::Stream; | ||
use futures_util::stream as futures_stream; | ||
|
||
pub struct ListObjectsV2Paginated { | ||
client: Client, | ||
args: ListObjectsV2Args, | ||
} | ||
|
||
impl ListObjectsV2Paginated { | ||
pub fn new(client: Client, args: ListObjectsV2Args) -> Self { | ||
ListObjectsV2Paginated { client, args } | ||
} | ||
|
||
pub async fn stream(self) -> impl Stream<Item = Result<ListObjectsV2Response, Error>> + Unpin { | ||
Box::pin(futures_stream::unfold( | ||
(self.client, self.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