Skip to content

Commit 8476880

Browse files
RickBullottagibfahn
authored andcommitted
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: #11363 Fixes: #11352 Refs: #11316 Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]>
1 parent eff9252 commit 8476880

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

doc/api/stream.md

+5-8
Original file line numberDiff line numberDiff line change
@@ -920,24 +920,21 @@ added: v0.9.4
920920
* `encoding` {string} The encoding to use.
921921
* Returns: `this`
922922

923-
The `readable.setEncoding()` method sets the default character encoding for
923+
The `readable.setEncoding()` method sets the character encoding for
924924
data read from the Readable stream.
925925

926-
Setting an encoding causes the stream data
927-
to be returned as string of the specified encoding rather than as `Buffer`
926+
By default, no encoding is assigned and stream data will be returned as
927+
`Buffer` objects. Setting an encoding causes the stream data
928+
to be returned as strings of the specified encoding rather than as `Buffer`
928929
objects. For instance, calling `readable.setEncoding('utf8')` will cause the
929-
output data will be interpreted as UTF-8 data, and passed as strings. Calling
930+
output data to be interpreted as UTF-8 data, and passed as strings. Calling
930931
`readable.setEncoding('hex')` will cause the data to be encoded in hexadecimal
931932
string format.
932933

933934
The Readable stream will properly handle multi-byte characters delivered through
934935
the stream that would otherwise become improperly decoded if simply pulled from
935936
the stream as `Buffer` objects.
936937

937-
Encoding can be disabled by calling `readable.setEncoding(null)`. This approach
938-
is useful when working with binary data or with large multi-byte strings spread
939-
out over multiple chunks.
940-
941938
```js
942939
const readable = getReadableStreamSomehow();
943940
readable.setEncoding('utf8');

0 commit comments

Comments
 (0)