Skip to content

Instantly share code, notes, and snippets.

@mudgen
Created November 12, 2012 00:05
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 mudgen/4056821 to your computer and use it in GitHub Desktop.
Save mudgen/4056821 to your computer and use it in GitHub Desktop.
(ns build.util
(:require [fs.core :as fs]
[clojure.java.io :as io])
(:import [java.util.zip ZipOutputStream
ZipEntry]))
(defn zip-dir
[name dir]
(with-open [zip-out (ZipOutputStream. (io/output-stream (fs/absolute-path name)))]
(let [read-buffer (make-array Byte/TYPE 2156)]
(doseq [file (map #(str dir "/" %) (fs/list-dir dir))]
(.putNextEntry zip-out (ZipEntry. file))
(with-open [zip-in (io/input-stream file)]
(loop [bytes (.read zip-in read-buffer)]
(if (not= bytes -1)
(do
(.write zip-out read-buffer 0 bytes)
(recur (.read zip-in read-buffer))))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment