Skip to content
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

Merged
merged 1 commit into from
Sep 27, 2020

Conversation

vbarzana
Copy link
Contributor

@vbarzana vbarzana commented Sep 25, 2020

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 addition, the example is fixed
My 2 cents!
Thanks,
Victor

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added crypto Issues and PRs related to the crypto subsystem. doc Issues and PRs related to the documentations. labels Sep 25, 2020
Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thank you!

Comment on lines 1033 to 1034
hash.setEncoding('hex');
input.pipe(hash).pipe(process.stdout);
Copy link
Member

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?

Suggested change
hash.setEncoding('hex');
input.pipe(hash).pipe(process.stdout);
input.pipe(hash).setEncoding('hex').pipe(process.stdout);

Copy link
Contributor Author

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!

Copy link
Member

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 :)

Copy link
Contributor Author

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 😉

Copy link
Member

@tniessen tniessen left a 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.

@vbarzana
Copy link
Contributor Author

@tniessen good point :), my concern here's that the end user is human, and may be expecting to see a readable output.

@tniessen
Copy link
Member

@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!

@addaleax addaleax added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Sep 25, 2020
@vbarzana vbarzana changed the title Setting the encoding to hex before piping the hash doc: Setting the encoding to hex before piping the hash Sep 25, 2020
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>
@Trott
Copy link
Member

Trott commented Sep 27, 2020

Landed in c15a227.

Thanks for the contribution! 🎉

@vbarzana vbarzana deleted the patch-1 branch September 29, 2020 06:25
MylesBorins pushed a commit that referenced this pull request Sep 29, 2020
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>
@MylesBorins MylesBorins mentioned this pull request Sep 29, 2020
joesepi pushed a commit to joesepi/node that referenced this pull request Jan 8, 2021
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. crypto Issues and PRs related to the crypto subsystem. doc Issues and PRs related to the documentations.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants