-
-
Save jcromartie/dda2e42a45226972aee5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn store | |
"Stores the given input (file, stream, etc.) as a document. Returns the new document ID." | |
[input] | |
(let [temp-file (file (File/createTempFile "anybillfs-store" nil))] | |
(with-open [in (input-stream input) | |
out (output-stream temp-file) | |
digest-stream (DigestOutputStream. out (MessageDigest/getInstance "SHA-1"))] | |
(copy in out) | |
(let [id (hexbytes (.digest (.getMessageDigest digest-stream))) | |
dest-file (file-for-id id)] | |
(make-parents dest-file) | |
(assert (true? (.renameTo temp-file dest-file))) | |
id)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment