diff --git a/blobstore/src/main/clojure/org/jclouds/blobstore.clj b/blobstore/src/main/clojure/org/jclouds/blobstore.clj index 74cfc3a0d1..51a679a4f2 100644 --- a/blobstore/src/main/clojure/org/jclouds/blobstore.clj +++ b/blobstore/src/main/clojure/org/jclouds/blobstore.clj @@ -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))] diff --git a/blobstore/src/test/clojure/org/jclouds/blobstore_test.clj b/blobstore/src/test/clojure/org/jclouds/blobstore_test.clj index 6c85903352..6fc0f8798e 100644 --- a/blobstore/src/test/clojure/org/jclouds/blobstore_test.clj +++ b/blobstore/src/test/clojure/org/jclouds/blobstore_test.clj @@ -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"