-
Notifications
You must be signed in to change notification settings - Fork 30k
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
doc: Setting the encoding to hex before piping the hash #35338
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.
Nice, thank you!
doc/api/crypto.md
Outdated
hash.setEncoding('hex'); | ||
input.pipe(hash).pipe(process.stdout); |
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 completely optional, but maybe this way it becomes a bit more obvious where the hex encoding takes place?
hash.setEncoding('hex'); | |
input.pipe(hash).pipe(process.stdout); | |
input.pipe(hash).setEncoding('hex').pipe(process.stdout); |
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.
Yep that would work, do you want me to submit another commit with your suggestion? Thank you!
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.
@vbarzana You can just add that commit to this PR, or use the “Commit suggestion” button here in the Github interface :)
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.
Done! Thank you, didn't see the button cause I was on the mobile 😉
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.
Note that the status quo is not "wrong". It correctly writes the hash in its binary form to the data stream process.stdout
, which might happen to be a terminal, in which case the output simply wouldn't be human readable.
@tniessen good point :), my concern here's that the end user is human, and may be expecting to see a readable output. |
@vbarzana I completely agree, which is why I already approved your suggestion :) I just wanted to point out that it's not wrong per se. Thank you for your contribution! |
I found out that piping a hash to the stdout output would print a non-hex set of characters, however, the examples are intended to print out a hex-encoded output so, my proposal here is simple, we set the encoding to `hex` before piping the response of the hash algo by calling `hash.setEncoding('hex');`. With this the example is fixed PR-URL: nodejs#35338 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Landed in c15a227. Thanks for the contribution! 🎉 |
I found out that piping a hash to the stdout output would print a non-hex set of characters, however, the examples are intended to print out a hex-encoded output so, my proposal here is simple, we set the encoding to `hex` before piping the response of the hash algo by calling `hash.setEncoding('hex');`. With this the example is fixed PR-URL: #35338 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
I found out that piping a hash to the stdout output would print a non-hex set of characters, however, the examples are intended to print out a hex-encoded output so, my proposal here is simple, we set the encoding to `hex` before piping the response of the hash algo by calling `hash.setEncoding('hex');`. With this the example is fixed PR-URL: nodejs#35338 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
I found out that piping a hash to the stdout output would print a non-hex set of characters, however, the examples are intended to print out a hex-encoded output so, my proposal here is simple, we set the encoding to
hex
before piping the response of the hash algo by callinghash.setEncoding('hex');
. With this addition, the example is fixedMy 2 cents!
Thanks,
Victor
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes