Created
June 9, 2012 00:53
-
-
Save Frozenlock/2898908 to your computer and use it in GitHub Desktop.
Clojure: spit directly to zip
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 spit-to-zip | |
"Put the content in filename and zip it into zip-filename. Accept | |
one or more filename/content." | |
[zip-filename filename content & others] | |
(with-open [zip (java.util.zip.ZipOutputStream. | |
(clojure.java.io/output-stream zip-filename))] | |
(let [add-entry (fn [name cont remain] | |
(-> zip (.putNextEntry (java.util.zip.ZipEntry. name))) | |
(doto (java.io.PrintStream. zip true) | |
(.println content)) | |
(when (seq remain) | |
(recur (first remain) (second remain) (drop 2 remain))))] | |
(add-entry filename content others)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There's an error in the 10th line s/content/cont