X-Git-Url: https://njoseph.me/gitweb/babashka-scripts.git/blobdiff_plain/f1d839f5e616cf6f3b121c3b34a4fd16b2200a8c..9da8be80d72b89328d70b47b71050251e32c470a:/lib.clj diff --git a/lib.clj b/lib.clj index 86dc702..5f216d1 100644 --- a/lib.clj +++ b/lib.clj @@ -1,7 +1,9 @@ -; +; Common utility functions used by scripts (import '[java.nio.file Files FileSystems CopyOption StandardCopyOption]) +(require '[org.httpkit.client :as http]) + (defn extract-file-from-zip [zip-file-name source destination] (let [zip-file (io/file zip-file-name) @@ -9,10 +11,16 @@ 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) + (Files/copy file-in-zip + (.toPath dest) (into-array CopyOption [StandardCopyOption/REPLACE_EXISTING])))) -(defn expand-home [s] +(defn expand-home + [s] (if (.startsWith s "~") (clojure.string/replace-first s "~" (System/getProperty "user.home")) s)) + +(defn download-binary + [url destination] + (io/copy (:body @(http/get url)) (io/file destination)))