Last active
January 2, 2016 23:49
-
-
Save ihercowitz/8378387 to your computer and use it in GitHub Desktop.
Ring play:
- Base64 encoder
- Base64 decoder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
Compress string:
=> (-> (compress "teste") b64-encode)
"H4sIAAAAAAAAAAtJLS5JBQALZnUnBQAAAA=="