feat: Make GCS list return a stream, by wrapping its still-sync API

pull/24376/head
Carol (Nichols || Goulding) 2020-06-10 10:56:29 -04:00
parent d83c410a5c
commit 4ad805863f
1 changed files with 14 additions and 1 deletions

View File

@ -157,7 +157,20 @@ impl GoogleCloudStorage {
&'a self,
prefix: Option<&'a str>,
) -> InternalResult<impl Stream<Item = InternalResult<Vec<String>>> + 'a> {
Ok(stream::empty())
let bucket_name = self.bucket_name.clone();
let prefix = prefix.map(|p| p.to_string());
let objects = tokio::task::spawn_blocking(move || match prefix {
Some(prefix) => cloud_storage::Object::list_prefix(&bucket_name, &prefix),
None => cloud_storage::Object::list(&bucket_name),
})
.await
.context(UnableToListDataFromGcs)?
.context(UnableToListDataFromGcs2)?;
Ok(futures::stream::once(async move {
Ok(objects.into_iter().map(|o| o.name).collect())
}))
}
}