Skip to content

Instantly share code, notes, and snippets.

@ihercowitz
Last active January 2, 2016 23:49
Show Gist options
  • Save ihercowitz/8378387 to your computer and use it in GitHub Desktop.
Save ihercowitz/8378387 to your computer and use it in GitHub Desktop.
Ring play: - Base64 encoder - Base64 decoder
(require '[ring.util.codec :as codec])
(defn compress [t]
(let [bout (java.io.ByteArrayOutputStream.)
out (java.uil.zip.GZIPOutputStream. bout)]
(clojure.java.io/copy t out)
(.close out)
(.toByteArray bout)))
(defn b64-encode [byte-array] (codec/base64-encode byte-array))
(defn b64-decode [t] (apply str (map char (codec/base64-decode t))))
@ihercowitz
Copy link
Author

Usage:
Compress string:

=> (-> (compress "teste") b64-encode)
"H4sIAAAAAAAAAAtJLS5JBQALZnUnBQAAAA=="

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment