Last active
March 7, 2020 21:36
-
-
Save dfuenzalida/cb5056bfa0743200f787185d3275026e to your computer and use it in GitHub Desktop.
InputStream to Base64 stream
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
;; An example InputStream made of 128 bytes: | |
(defn bytes-is [] | |
(java.io.ByteArrayInputStream. (into-array Byte/TYPE (range 128)))) | |
(defn b64encode [s] | |
(String. (.encode (java.util.Base64/getEncoder) (.getBytes s)))) | |
;; Now we read the input stream *in memory* (with slurp) and encode as base64: | |
(-> (bytes-is) slurp b64encode) | |
;; => "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJC...n8=" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment