Skip to content

Instantly share code, notes, and snippets.

@igrishaev
Last active February 28, 2018 12:23
Show Gist options
  • Save igrishaev/628e28f3f4732f46e5687d58ebd7611b to your computer and use it in GitHub Desktop.
Save igrishaev/628e28f3f4732f46e5687d58ebd7611b to your computer and use it in GitHub Desktop.
(:import java.util.zip.ZipEntry
java.util.zip.ZipInputStream))
(defn- ^ZipInputStream get-stream
[url]
(let [resp (client/get url {:as :stream})]
(ZipInputStream. (:body resp))))
(def ^:private
re-xlsx #".*(?i)\.xlsx$")
(def ^:private
re-csv #".*(?i)\.csv$")
(defn- matches-ext [filename ext]
(str/ends-with? (str/lower-case filename) (str/lower-case ext)))
(defn- seek-stream
[^ZipInputStream stream ^java.util.regex.Pattern re]
(loop []
(if-let [entry (.getNextEntry stream)]
(let [filename (.getName entry)]
(if (re-matches re filename)
stream
(recur)))
(raise! "Cannot find a file by regex %s" re))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment