Add list-blobs function to create a lazy-seq of blobs.

list-container is still available as a low-level call, but list-blobs
should be preferred going forward since it doesn't need to be manually
paginated.
This commit is contained in:
Phil Hagelberg 2010-05-26 15:22:13 -10:00
parent 6cee7daa37
commit e64fd52a60
1 changed files with 19 additions and 1 deletions

View File

@ -112,7 +112,8 @@ Options can also be specified for extension modules
:recursive #(when %2 (.recursive %1))})
(defn list-container
"List a container. Options are:
"Low-level container listing. Use list-blobs where possible since
it's higher-level and returns a lazy seq. Options are:
:after-marker string
:in-direcory path
:max-results n
@ -131,6 +132,23 @@ Options can also be specified for extension modules
(.list blobstore container-name list-options))
(apply list-container *blobstore* blobstore args)))
(defn- list-blobs-chunk [container prefix blobstore & [marker]]
(apply blobstore/list-container blobstore container
:in-directory prefix (when (string? marker)
[:after-marker marker])))
(defn- list-blobs-chunks [container prefix blobstore marker]
(when marker
(let [chunk (list-blobs-chunk container prefix blobstore marker)]
(lazy-seq (cons chunk
(list-blobs-chunks container prefix blobstore
(.getNextMarker chunk)))))))
(defn list-blobs
"Returns a lazy seq of all blobs in the given container."
([container prefix blobstore]
(apply concat (list-blobs-chunks container prefix blobstore :start))))
(defn locations
"Retrieve the available container locations for the blobstore context."
([] (locations *blobstore*))