Skip to content

Instantly share code, notes, and snippets.

@marcandrefontaine
Last active February 4, 2016 03:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcandrefontaine/103e4d2200e19eb6d5a8 to your computer and use it in GitHub Desktop.
Save marcandrefontaine/103e4d2200e19eb6d5a8 to your computer and use it in GitHub Desktop.
b64+inflate
(ns mf
(:require [clojure.data.codec.base64 :as b64])
(:import (java.util.zip Inflater)))
(defn decompress-content [content]
(let [decoded (b64/decode (.getBytes content))
buffer-size (* 2 (count decoded))
result (byte-array buffer-size)
inflater (Inflater.)
]
(. inflater setInput decoded 0 (count decoded))
(loop [return ""]
(if (. inflater finished)
return
(let [nb (. inflater inflate result 0 buffer-size)]
(recur (str return (String. result 0 nb "UTF-8")))
)
)
)
))
(decompress-content "eJzzt7KwUiouSXHOSSwuVrIysqoutjK2UiosqVSyzrQyNDAwsC62MgUqyUxJLVYCss2slFz8Q518XJWsawEyGRG/")
=> "O:8:\"stdClass\":2:{s:3:\"qty\";i:1000;s:5:\"sides\";s:6:\"DOUBLE\";}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment