taoensso / nippy

The fastest serialization library for Clojure
https://www.taoensso.com/nippy
Eclipse Public License 1.0
1.04k stars 60 forks source link

Serialise deserialise with nippy to a string #127

Closed piotr-yuxuan closed 4 years ago

piotr-yuxuan commented 4 years ago

Thank you for this library. Indeed it's quite fast! I believe it might be worth add in the readme an example of how to serialise and then deserialise to a string. The naive approach is to use slurp on the byte[] array returned by nippy. This doesn't work.

(defn nippy-serialise-to-string
  ^String [o]
  (.encodeToString (java.util.Base64/getEncoder) (nippy/freeze o {})))

(defn nippy-deserialise-from-string
  ^Object [^String s]
  (nippy/thaw (.decode (java.util.Base64/getDecoder) s)))
piotr-yuxuan commented 4 years ago

Will push a PR when I have some time.

ptaoussanis commented 4 years ago

Just added manually.