Add optional print-dup? arg to freeze-to-stream! (default to true)
This commit is contained in:
parent
03684b6d28
commit
f056abc0e8
1 changed files with 9 additions and 6 deletions
|
|
@ -150,17 +150,20 @@
|
|||
|
||||
(defn freeze-to-stream!
|
||||
"Serializes x to given output stream."
|
||||
[data-output-stream x]
|
||||
(binding [*print-dup* true] ; For `pr-str`
|
||||
(freeze-to-stream!* data-output-stream x)))
|
||||
([data-output-stream x] ; For <= 1.0.1 compatibility
|
||||
(freeze-to-stream! data-output-stream x true))
|
||||
([data-output-stream x print-dup?]
|
||||
(binding [*print-dup* print-dup?] ; For `pr-str`
|
||||
(freeze-to-stream!* data-output-stream x))))
|
||||
|
||||
(defn freeze-to-bytes
|
||||
"Serializes x to a byte array and returns the array."
|
||||
^bytes [x & {:keys [compress?]
|
||||
:or {compress? true}}]
|
||||
^bytes [x & {:keys [compress? print-dup?]
|
||||
:or {compress? true
|
||||
print-dup? true}}]
|
||||
(let [ba (ByteArrayOutputStream.)
|
||||
stream (DataOutputStream. ba)]
|
||||
(freeze-to-stream! stream x)
|
||||
(freeze-to-stream! stream x print-dup?)
|
||||
(let [ba (.toByteArray ba)]
|
||||
(if compress? (Snappy/compress ba) ba))))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue