doc: set encoding to hex before piping hash

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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Victor Antonio Barzana Crespo authored and Myles Borins committed 2020-09-29 11:43:24 -04:00
1 parent f2635b317e
commit 857e321baf
1 file changed
+1 -1
+1 -1
View File
@@ -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: