aboutsummaryrefslogtreecommitdiff
path: root/src/lux/packager/lib.clj
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lux/packager/lib.clj40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/lux/packager/lib.clj b/src/lux/packager/lib.clj
new file mode 100644
index 000000000..41f3143a0
--- /dev/null
+++ b/src/lux/packager/lib.clj
@@ -0,0 +1,40 @@
+;; Copyright (c) Eduardo Julian. All rights reserved.
+;; This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
+;; If a copy of the MPL was not distributed with this file,
+;; You can obtain one at http://mozilla.org/MPL/2.0/.
+
+(ns lux.packager.lib
+ (:require [lux.lib.loader :as &lib])
+ (:import (java.io File
+ FileOutputStream)
+ java.util.zip.GZIPOutputStream
+ (org.apache.commons.compress.archivers.tar TarArchiveEntry
+ TarArchiveOutputStream)
+ ))
+
+;; [Utils]
+(defn ^:private read-file [file]
+ (with-open [is (java.io.FileInputStream. file)]
+ (let [data (byte-array (.length file))]
+ (.read is data)
+ data)))
+
+(defn ^:private add-to-tar! [prefix ^File file os]
+ "(-> Text File TarArchiveOutputStream Unit)"
+ (let [file-name (str prefix "/" (.getName file))]
+ (if (.isDirectory file)
+ (doseq [file (seq (.listFiles file))]
+ (add-to-tar! file-name file os))
+ (doto os
+ (.putArchiveEntry (doto (new TarArchiveEntry file-name)
+ (.setSize (.length file))))
+ (.write (read-file file))
+ (.closeArchiveEntry)))))
+
+;; [Exports]
+(defn package [output-lib-name ^File source-dir]
+ "(-> Text File Unit)"
+ (with-open [out (->> (str output-lib-name &lib/lib-ext) (new FileOutputStream) (new GZIPOutputStream) (new TarArchiveOutputStream))]
+ (doseq [file (seq (.listFiles source-dir))]
+ (add-to-tar! "" file out))
+ ))