Skip to content

Commit

Permalink
doc: set encoding to hex before piping hash
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
vbarzana authored and MylesBorins committed Sep 29, 2020
1 parent f2635b3 commit 857e321
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion doc/api/crypto.md
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ const fs = require('fs');
const hash = crypto.createHash('sha256');

const input = fs.createReadStream('test.js');
input.pipe(hash).pipe(process.stdout);
input.pipe(hash).setEncoding('hex').pipe(process.stdout);
```

Example: Using the [`hash.update()`][] and [`hash.digest()`][] methods:
Expand Down

0 comments on commit 857e321

Please sign in to comment.