Skip to content

Commit e400ef9

Browse files
RickBullottaMylesBorins
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 092bba5 commit e400ef9

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
@@ -926,24 +926,21 @@ added: v0.9.4
926926
* `encoding` {string} The encoding to use.
927927
* Returns: `this`
928928

929-
The `readable.setEncoding()` method sets the default character encoding for
929+
The `readable.setEncoding()` method sets the character encoding for
930930
data read from the Readable stream.
931931

932-
Setting an encoding causes the stream data
933-
to be returned as string of the specified encoding rather than as `Buffer`
932+
By default, no encoding is assigned and stream data will be returned as
933+
`Buffer` objects. Setting an encoding causes the stream data
934+
to be returned as strings of the specified encoding rather than as `Buffer`
934935
objects. For instance, calling `readable.setEncoding('utf8')` will cause the
935-
output data will be interpreted as UTF-8 data, and passed as strings. Calling
936+
output data to be interpreted as UTF-8 data, and passed as strings. Calling
936937
`readable.setEncoding('hex')` will cause the data to be encoded in hexadecimal
937938
string format.
938939

939940
The Readable stream will properly handle multi-byte characters delivered through
940941
the stream that would otherwise become improperly decoded if simply pulled from
941942
the stream as `Buffer` objects.
942943

943-
Encoding can be disabled by calling `readable.setEncoding(null)`. This approach
944-
is useful when working with binary data or with large multi-byte strings spread
945-
out over multiple chunks.
946-
947944
```js
948945
const readable = getReadableStreamSomehow();
949946
readable.setEncoding('utf8');

0 commit comments

Comments
 (0)