]> njoseph.me Git - babashka-scripts.git/blame - lib.clj
Replace babashka/curl with httpkit.client
[babashka-scripts.git] / lib.clj
CommitLineData
1770a260 1; Common utility functions used by scripts
f1d839f5
JN
2
3(import '[java.nio.file Files FileSystems CopyOption StandardCopyOption])
4
9da8be80
JN
5(require '[org.httpkit.client :as http])
6
f1d839f5
JN
7(defn extract-file-from-zip
8 [zip-file-name source destination]
9 (let [zip-file (io/file zip-file-name)
10 src (io/file source)
11 dest (io/file destination)
12 fs (FileSystems/newFileSystem (.toPath zip-file) nil)
13 file-in-zip (.getPath fs source (into-array String []))]
0b0f2aa3
JN
14 (Files/copy file-in-zip
15 (.toPath dest)
f1d839f5
JN
16 (into-array CopyOption [StandardCopyOption/REPLACE_EXISTING]))))
17
0b0f2aa3
JN
18(defn expand-home
19 [s]
f1d839f5
JN
20 (if (.startsWith s "~")
21 (clojure.string/replace-first s "~" (System/getProperty "user.home"))
22 s))
9da8be80
JN
23
24(defn download-binary
25 [url destination]
26 (io/copy (:body @(http/get url)) (io/file destination)))