Skip to content

Instantly share code, notes, and snippets.

Created April 1, 2012 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/2279100 to your computer and use it in GitHub Desktop.
Save anonymous/2279100 to your computer and use it in GitHub Desktop.
(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)))
(.println (java.io.PrintWriter. zip true) cont)
(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