X-Git-Url: https://njoseph.me/gitweb/babashka-scripts.git/blobdiff_plain/f7a7c8852fc7f3a47f858ad4fbf6b177735f52c0..f1d839f5e616cf6f3b121c3b34a4fd16b2200a8c:/lib.clj diff --git a/lib.clj b/lib.clj new file mode 100644 index 0000000..86dc702 --- /dev/null +++ b/lib.clj @@ -0,0 +1,18 @@ +; + +(import '[java.nio.file Files FileSystems CopyOption StandardCopyOption]) + +(defn extract-file-from-zip + [zip-file-name source destination] + (let [zip-file (io/file zip-file-name) + src (io/file source) + dest (io/file destination) + fs (FileSystems/newFileSystem (.toPath zip-file) nil) + file-in-zip (.getPath fs source (into-array String []))] + (Files/copy file-in-zip (.toPath dest) + (into-array CopyOption [StandardCopyOption/REPLACE_EXISTING])))) + +(defn expand-home [s] + (if (.startsWith s "~") + (clojure.string/replace-first s "~" (System/getProperty "user.home")) + s))