-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Directly coerce to DataOutputStream without using output-stream #14
Conversation
This is problematic because io/output-stream in clojure adds yet an other buffer in the middle which is uncessary since all instances in the code are OutputStream already and DataOutputStream already accepts it, secondly it creates corruption while using different streams like GZIPOutputStream for unknown reasons the BufferedOutputStream introduced by io/output-stream is preventing the last flush thus corrupting the output.
Codecov Report
@@ Coverage Diff @@
## develop #14 +/- ##
======================================
Coverage 100% 100%
======================================
Files 13 13
Lines 805 804 -1
======================================
- Hits 805 804 -1
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the investigation and fixes! In hindsight, this is an obvious symmetry of #13 which dealt with the same issue on the decoding side.
src/clj_cbor/core.clj
Outdated
@@ -78,15 +78,6 @@ | |||
|
|||
;; ## Encoding Functions | |||
|
|||
(defn- data-output-stream |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'd be better to keep this function and do something similar to 760124f - if the argument is already a DataOutputStream
then return it, if it is an OutputStream
already then wrap it directly, otherwise use io/output-stream
to coerce it before wrapping.
src/clj_cbor/core.clj
Outdated
(encode-seq encoder output values)) | ||
(.toByteArray buffer))) | ||
([encoder ^OutputStream output values] | ||
(let [data-output (data-output-stream output)] | ||
(let [data-output (DataOutputStream. output)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would double-wrap an existing DataOutputStream
, which is probably fine in practice but not ideal.
@greglook Oh! that's very good point, I totally forgot the double wrap indeed, a bit stupid. So I did adapt the function and only call it where the stream comes externally. I hope I got it right this time. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
This is problematic because io/output-stream in clojure adds yet an
other buffer in the middle which is uncessary since all instances in the
code are OutputStream already and DataOutputStream already accepts it,
secondly it creates corruption while using different streams like
GZIPOutputStream for unknown reasons the BufferedOutputStream introduced
by io/output-stream is preventing the last flush thus corrupting the
output.
To reproduce the bug try this:
The code above works if we do:
As you can see we directly provide ourself the
DataOutputStream
thus in the code above we don't call io/output-stream as explained.