Created
November 12, 2012 00:05
-
-
Save mudgen/4056821 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
(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