     (let [fetch1
           (fn [k]
             (tundra/catcht
-             (let [obj (s3/get-object creds bucket k)
-                   ba  (byte-array (-> obj :metadata :content-length))]
-               (.readFully (DataInputStream. (:content obj)) ba)
-               ba)))]
+              (let [obj (s3/get-object creds bucket k)]
+                (with-open
+                    [^com.amazonaws.services.s3.model.S3ObjectInputStream cnt
+                     (:content obj)]
+                  (let [ba (byte-array (enc/have enc/pos-int?
+                                         (-> obj :metadata :content-length)))]
+                    (.readFully (DataInputStream. cnt) ba)
+                    ba)))))]
       (->> (mapv #(future (fetch1 %)) ks)
            (mapv deref)))))
 

  {:author "Peter Taoussanis"}
  (:require [clojure.string          :as str]
            [aws.sdk.s3              :as s3]
            [taoensso.encore         :as encore]
            [taoensso.timbre         :as timbre]
            [taoensso.carmine.tundra :as tundra])
  (:import  [java.io ByteArrayInputStream DataInputStream]

(defrecord S3DataStore [creds bucket]
  IDataStore
  (put-key [this k v]
    (have? enc/bytes? v)
    (let [reply (try (s3/put-object creds bucket k (ByteArrayInputStream. v)
                       {:content-length (count v)
                        ;; Nb! Prevents overwriting with corrupted data:
