mirror of https://github.com/apache/jclouds.git
added get-blob-stream helper and corresponding test
This commit is contained in:
parent
a58ab85b7e
commit
25bc2c0691
|
@ -237,6 +237,13 @@ Options can also be specified for extension modules
|
|||
([container-name path #^BlobStore blobstore]
|
||||
(.getBlob blobstore container-name path)))
|
||||
|
||||
(defn get-blob-stream
|
||||
"Get an inputstream from the blob at a given path"
|
||||
([container-name path]
|
||||
(get-blob-stream container-name path *blobstore*))
|
||||
([container-name path #^BlobStore blobstore]
|
||||
(.getInput(.getPayload(.getBlob blobstore container-name path)))))
|
||||
|
||||
(defn remove-blob
|
||||
"Remove blob from given path"
|
||||
([container-name path]
|
||||
|
@ -311,7 +318,7 @@ container, name, string -> etag"
|
|||
& [retries]]
|
||||
(let [blob (get-blob container-name name blobstore)
|
||||
digest-stream (DigestOutputStream.
|
||||
target (MessageDigest/getInstance "MD5"))]
|
||||
target (.md5(.crypto (.utils (blobstore-context blobstore)))))]
|
||||
(.writeTo (.getPayload blob) digest-stream)
|
||||
(let [digest (.digest (.getMessageDigest digest-stream))
|
||||
metadata-digest (.getContentMD5 (.getPayload blob))]
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
(:use [org.jclouds.blobstore] :reload-all)
|
||||
(:use [clojure.test])
|
||||
(:import [org.jclouds.blobstore BlobStoreContextFactory]
|
||||
[java.io ByteArrayOutputStream]))
|
||||
[java.io ByteArrayOutputStream]
|
||||
[org.jclouds.util Utils]))
|
||||
|
||||
(defn clean-stub-fixture
|
||||
"This should allow basic tests to easily be run with another service."
|
||||
|
@ -73,6 +74,12 @@
|
|||
(is (= 3 (count (list-container "container" :with-details true))))
|
||||
(is (= 1 (count (list-container "container" :in-directory "dir")))))
|
||||
|
||||
(deftest get-blob-test
|
||||
(is (create-container "blob"))
|
||||
(is (upload-blob "blob" "blob1" "blob1"))
|
||||
(is (upload-blob "blob" "blob2" "blob2"))
|
||||
(is (= "blob2" (Utils/toStringAndClose (get-blob-stream "blob" "blob2")))))
|
||||
|
||||
(deftest download-blob-test
|
||||
(let [name "test"
|
||||
container-name "test-container"
|
||||
|
|
Loading…
Reference in New Issue