diff options
author | Rick Bullotta <RickBullotta@users.noreply.github.com> | 2017-05-19 12:59:25 +0100 |
---|---|---|
committer | Myles Borins <mylesborins@google.com> | 2017-07-17 15:14:54 -0400 |
commit | e400ef9a76bf4728dba95c57f38677b88d7088ba (patch) | |
tree | bf34f069311135814a8c93d99a33e197183aff6e | |
parent | 092bba5cbfe03de495d2d2e9a7b1bd5f07cec3dd (diff) | |
download | node-new-e400ef9a76bf4728dba95c57f38677b88d7088ba.tar.gz |
doc: don't suggest setEncoding for binary streams
Removed an incorrect reference to the use of setEncoding(null) as the
proper way to handling binary streams or to disable encoding, and
explained that the default encoding is "no encoding", and that this is
the correct approach for dealing with binary data via Buffers.
PR-URL: https://github.com/nodejs/node/pull/11363
Fixes: https://github.com/nodejs/node/issues/11352
Refs: https://github.com/nodejs/node/issues/11316
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
-rw-r--r-- | doc/api/stream.md | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/doc/api/stream.md b/doc/api/stream.md index 7987eb8265..e3fb35deba 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -926,13 +926,14 @@ added: v0.9.4 * `encoding` {string} The encoding to use. * Returns: `this` -The `readable.setEncoding()` method sets the default character encoding for +The `readable.setEncoding()` method sets the character encoding for data read from the Readable stream. -Setting an encoding causes the stream data -to be returned as string of the specified encoding rather than as `Buffer` +By default, no encoding is assigned and stream data will be returned as +`Buffer` objects. Setting an encoding causes the stream data +to be returned as strings of the specified encoding rather than as `Buffer` objects. For instance, calling `readable.setEncoding('utf8')` will cause the -output data will be interpreted as UTF-8 data, and passed as strings. Calling +output data to be interpreted as UTF-8 data, and passed as strings. Calling `readable.setEncoding('hex')` will cause the data to be encoded in hexadecimal string format. @@ -940,10 +941,6 @@ The Readable stream will properly handle multi-byte characters delivered through the stream that would otherwise become improperly decoded if simply pulled from the stream as `Buffer` objects. -Encoding can be disabled by calling `readable.setEncoding(null)`. This approach -is useful when working with binary data or with large multi-byte strings spread -out over multiple chunks. - ```js const readable = getReadableStreamSomehow(); readable.setEncoding('utf8'); |