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!
|
(defn freeze-to-stream!
|
||||||
"Serializes x to given output stream."
|
"Serializes x to given output stream."
|
||||||
[data-output-stream x]
|
([data-output-stream x] ; For <= 1.0.1 compatibility
|
||||||
(binding [*print-dup* true] ; For `pr-str`
|
(freeze-to-stream! data-output-stream x true))
|
||||||
(freeze-to-stream!* data-output-stream x)))
|
([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
|
(defn freeze-to-bytes
|
||||||
"Serializes x to a byte array and returns the array."
|
"Serializes x to a byte array and returns the array."
|
||||||
^bytes [x & {:keys [compress?]
|
^bytes [x & {:keys [compress? print-dup?]
|
||||||
:or {compress? true}}]
|
:or {compress? true
|
||||||
|
print-dup? true}}]
|
||||||
(let [ba (ByteArrayOutputStream.)
|
(let [ba (ByteArrayOutputStream.)
|
||||||
stream (DataOutputStream. ba)]
|
stream (DataOutputStream. ba)]
|
||||||
(freeze-to-stream! stream x)
|
(freeze-to-stream! stream x print-dup?)
|
||||||
(let [ba (.toByteArray ba)]
|
(let [ba (.toByteArray ba)]
|
||||||
(if compress? (Snappy/compress ba) ba))))
|
(if compress? (Snappy/compress ba) ba))))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue