     [clojure.string :as string]
     [vault.blob.core :as blob :refer [BlobStore]])
   (:import
-    (java.io
-      File)))
+    java.io.File
+    java.util.Date))
 
 
 ;; HELPER FUNCTIONS
 
-(defn- hashid->file
+(defn- id->file
   ^File
   [root id]
   (let [id (blob/hash-id id)
         {:keys [algorithm digest]} id]
     (io/file root
-             (name algorithm)
-             (subs digest 0 3)
-             (subs digest 3 6)
-             (subs digest 6))))
+      (name algorithm)
+      (subs digest 0 3)
+      (subs digest 3 6)
+      (subs digest 6))))
 
 
-(defn- file->hashid
+(defn- file->id
   [root file]
   (let [root (str root)
         file (str file)]

        (.setWritable file false false))))


  (-remove! [this id]
    (let [file (hashid->file (:root this) id)]
      (when (.exists file)
        (.delete file)))))


(defn file-store

(extend-protocol BlobStore
  FileBlobStore

  (enumerate [this opts]
    (->> (enumerate-files (:root this))
         (map (partial file->id (:root this)))
         (blob/select-ids opts)))


  (stat [this id]
    (when-blob-file this id
      {:size (.length file)
       :stored-at (Date. (.lastModified file))
       :location (.toURI file)}))


  (open [this id]
    (when-blob-file this id
      (io/input-stream file)))


  (store! [this blob]
    (let [{:keys [id content]} blob
          file (id->file (:root this) id)]
      (when-not (.exists file)
        (io/make-parents file)
        ; For some reason, io/copy is much faster than byte-streams/transfer here.
