-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
zlib: expose amount of data read for engines #13088
Conversation
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, particularly for the test case. You'll need to add documentation before this can land, and shorten the commit message to 50 characters.
Added bytesRead property to Zlib engines Refs: nodejs#8874
fc8498f
to
7aa6e2b
Compare
@sam-github I've fixed the commit message, and I'll work on the documentation. I have one question though: What is the purpose of the |
I think the public method was actually supposed to enable re-use of zlib contexts, probably for efficiency. It was added in 71ae175, but that was a long time ago and I’m not sure if @indutny remembers more details. 😄 Internally, the method is used for e.g. resetting after a member of a gzip file containing multiple members has been decompressed ( I think it’s okay to leave it alone and not reset the counter. |
@sam-github I've added some documentation. Let me know if it needs any changes. |
@@ -385,6 +385,12 @@ added: v0.5.8 | |||
Not exported by the `zlib` module. It is documented here because it is the base | |||
class of the compressor/decompressor classes. | |||
|
|||
### zlib.bytesRead |
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.
Can you add
<!-- YAML
added: REPLACEME
-->
directly below this heading?
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.
Added
const write = () => { | ||
target.write(Buffer.from([buffer[writer.size++]])); | ||
if (writer.size < buffer.length) { | ||
setTimeout(write, 25); |
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 looks a bit odd… I think what you want is to do something once the write finished, but the right way to do that would be to pass a callback to target.write()
, instead of relying on timeouts
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.
Ah, I didn't realize there were callbacks for these methods. That's a much better idea.
doc/api/zlib.md
Outdated
|
||
* {number} | ||
|
||
The `zlib.bytesRead` property specifies the number of bytes read by the engine. |
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.
bytes in -> zlib engine -> bytes out
: this is the bytes read by the engine from the encrypted stream (bytes out), or the other side (bytes in)? I suspect its bytes in, but it should be overwhelmingly clear from the docs, please, perhaps "bytes read by the engine before the bytes are processed (compressed or decompressed, as appropriate for the derived class)" <--- or change the language if its bytes read post processing.
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.
Yes, it's the bytes in. Description expanded.
Refactored bytesRead test to use callbacks instead of timers Refs: nodejs#8874
Thanks @AlexanderOMara, it looks good. |
Landed in e710036, thanks for the PR! |
Added bytesRead property to Zlib engines Fixes: #8874 PR-URL: #13088 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Sam Roberts <[email protected]>
Added bytesRead property to Zlib engines Fixes: #8874 PR-URL: #13088 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Sam Roberts <[email protected]>
Release team decided not to backport to v6.x, if you disagree let us know. @addaleax if you think this should go back to v6.x and would be willing to backport, tell us. |
The introduction of `.bytesRead` to zlib streams was unfortunate, because other streams in Node.js core use the exact opposite naming of `.bytesRead` and `.bytesWritten`. While one could see how the original naming makes sense in a `Transform` stream context, we should try to work towards more consistent APIs in core for these things. This introduces `zlib.bytesWritten` and documentation-only deprecates `zlib.bytesRead`. (Luckily, the old property name hasn’t even been around for a whole year yet.) Refs: nodejs#8874 Refs: nodejs#13088
The introduction of `.bytesRead` to zlib streams was unfortunate, because other streams in Node.js core use the exact opposite naming of `.bytesRead` and `.bytesWritten`. While one could see how the original naming makes sense in a `Transform` stream context, we should try to work towards more consistent APIs in core for these things. This introduces `zlib.bytesWritten` and documentation-only deprecates `zlib.bytesRead`. PR-URL: nodejs#19414 Refs: nodejs#8874 Refs: nodejs#13088 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Сковорода Никита Андреевич <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
The introduction of `.bytesRead` to zlib streams was unfortunate, because other streams in Node.js core use the exact opposite naming of `.bytesRead` and `.bytesWritten`. While one could see how the original naming makes sense in a `Transform` stream context, we should try to work towards more consistent APIs in core for these things. This introduces `zlib.bytesWritten` and documentation-only deprecates `zlib.bytesRead`. PR-URL: #19414 Refs: #8874 Refs: #13088 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Сковорода Никита Андреевич <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
The introduction of `.bytesRead` to zlib streams was unfortunate, because other streams in Node.js core use the exact opposite naming of `.bytesRead` and `.bytesWritten`. While one could see how the original naming makes sense in a `Transform` stream context, we should try to work towards more consistent APIs in core for these things. This introduces `zlib.bytesWritten` and documentation-only deprecates `zlib.bytesRead`. PR-URL: nodejs#19414 Refs: nodejs#8874 Refs: nodejs#13088 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Сковорода Никита Андреевич <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
Added bytesRead property to Zlib engines
Refs: #8874
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
Alternative to Pull Request #12939, broken into 2 separate commits.