chunk_id
large_stringlengths
36
36
doc_type
large_stringclasses
2 values
category
large_stringclasses
17 values
document
large_stringclasses
50 values
version_raw
large_stringclasses
590 values
chunk_index
int64
0
262
text
large_stringlengths
11
5.69k
file_path
large_stringclasses
882 values
8f835c14-eb31-5817-a056-44e922bfaf3f
docs
nodejs
nodejs_stream
6x
81
socket.on('end', () => { socket.end('The message was received but was not processed.\n'); }); // start the flow of data, discarding it. socket.resume(); }).listen(1337); ``` In addition to new Readable streams switching into flowing mode, pre-v0.10 style streams can be wrapped in a Readable class using t...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
fdd4f0b0-59b6-5ff7-8f79-79819d92950b
docs
nodejs
nodejs_stream
6x
82
Readable stream class internals. ### `readable.push('')`[#](#stream_readable_push) Use of `readable.push('')` is not recommended. Pushing a zero-byte string or `Buffer` to a stream that is not in object mode has an interesting side effect. Because it *is* a call to [`readable.push()`](#stream_readable_push_chunk_enc...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
efcf60ea-0f41-5bf5-9b2c-d7c63571f6b3
docs
nodejs
nodejs_stream
6x
83
This is not a problem in common cases with `latin1` or `ascii`. But it is advised to be mindful about this behavior when working with strings that could contain multi-byte characters.
large_dataset/raw/docs/nodejs/stream/stream_6x.md
8c0529d4-301f-5346-ae33-4a34b1b8fb42
docs
nodejs
nodejs_stream
7x
0
# Stream# Source: https://nodejs.org/docs/latest-v7.x/api/stream.html Version: 7.x ```None Stability: 2 - Stable ``` A stream is an abstract interface for working with streaming data in Node.js. The `stream` module provides a base API that makes it easy to build objects that implement the stream interface. There ar...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
ffbf5ee7-53f4-5d3f-a4a4-af7470ecce4f
docs
nodejs
nodejs_stream
7x
1
objects will rarely (if ever) have need to use the `stream` module directly. ## Organization of this Document[#](#stream_organization_of_this_document) This document is divided into two primary sections with a third section for additional notes. The first section explains the elements of the stream API that are requi...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
80c8166b-e617-5482-94c4-a2f92be94316
docs
nodejs
nodejs_stream
7x
2
[`net.Socket`](net.html#net_class_net_socket)). * [Transform](#stream_class_stream_transform) - Duplex streams that can modify or transform the data as it is written and read (for example [`zlib.createDeflate()`](zlib.html#zlib_zlib_createdeflate_options)). ### Object Mode[#](#stream_object_mode) All streams crea...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
d606a29a-b194-5421-989e-1dc2c070351b
docs
nodejs
nodejs_stream
7x
3
### Buffering[#](#stream_buffering) Both [Writable](#stream_class_stream_writable) and [Readable](#stream_class_stream_readable) streams will store data in an internal buffer that can be retrieved using `writable._writableState.getBuffer()` or `readable._readableState.buffer`, respectively. The amount of data potenti...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
f7ac08f5-5ea0-530e-95ab-849fb073d1e1
docs
nodejs
nodejs_stream
7x
4
underlying resource until the data currently buffered can be consumed (that is, the stream will stop calling the internal `readable._read()` method that is used to fill the read buffer). Data is buffered in Writable streams when the [`writable.write(chunk)`](#stream_writable_write_chunk_encoding_callback) method is ca...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
6f37767a-94e7-5b66-b468-4920a56c6b0c
docs
nodejs
nodejs_stream
7x
5
each maintain *two* separate internal buffers used for reading and writing, allowing each side to operate independently of the other while maintaining an appropriate and efficient flow of data. For example, [`net.Socket`](net.html#net_class_net_socket) instances are [Duplex](#stream_class_stream_duplex) streams whose R...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
81aaaa0e-fc85-561a-9f58-11ecd629bbc6
docs
nodejs
nodejs_stream
7x
6
// req is an http.IncomingMessage, which is a Readable Stream // res is an http.ServerResponse, which is a Writable Stream let body = ''; // Get the data as utf8 strings. // If an encoding is not set, Buffer objects will be received. req.setEncoding('utf8'); // Readable streams emit 'data' events once a...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
75879ad1-36b5-51e8-8e87-7f4ae33159ca
docs
nodejs
nodejs_stream
7x
7
[Writable](#stream_class_stream_writable) streams (such as `res` in the example) expose methods such as `write()` and `end()` that are used to write data onto the stream. [Readable](#stream_class_stream_readable) streams use the [`EventEmitter`](events.html#events_class_eventemitter) API for notifying application code...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
13cdd18a-0088-5e70-8064-5a17ee9c1ed7
docs
nodejs
nodejs_stream
7x
8
have no reason to call `require('stream')`. Developers wishing to implement new types of streams should refer to the section [API for Stream Implementers](#stream_api_for_stream_implementers). ### Writable Streams[#](#stream_writable_streams) Writable streams are an abstraction for a *destination* to which data is w...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
4019241e-e7ef-5f59-a1eb-dbc44903d96d
docs
nodejs
nodejs_stream
7x
9
the [Writable](#stream_class_stream_writable) interface. All [Writable](#stream_class_stream_writable) streams implement the interface defined by the `stream.Writable` class. While specific instances of [Writable](#stream_class_stream_writable) streams may differ in various ways, all Writable streams follow the same ...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
bb5225fd-1306-513a-a415-989424a76914
docs
nodejs
nodejs_stream
7x
10
##### Event: 'drain'[#](#stream_event_drain) Added in: v0.9.4 If a call to [`stream.write(chunk)`](#stream_writable_write_chunk_encoding_callback) returns `false`, the `'drain'` event will be emitted when it is appropriate to resume writing data to the stream. ```None // Write the data to the supplied writable strea...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
c527e47c-540b-5567-94be-625c253e2840
docs
nodejs
nodejs_stream
7x
11
##### Event: 'error'[#](#stream_event_error) Added in: v0.9.4 * [<Error>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) The `'error'` event is emitted if an error occurred while writing or piping data. The listener callback is passed a single `Error` argument when called. *...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
c7d03455-6e07-52f4-b640-ff6e3c6afef8
docs
nodejs
nodejs_stream
7x
12
##### Event: 'pipe'[#](#stream_event_pipe) Added in: v0.9.4 * `src` [<stream.Readable>](stream.html#stream_class_stream_readable) source stream that is piping to this writable The `'pipe'` event is emitted when the [`stream.pipe()`](#stream_readable_pipe_destination_options) method is called on a readable stream, ad...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
a8c446e2-5f93-524b-bc0d-ed5e6dfa19fd
docs
nodejs
nodejs_stream
7x
13
on a [Readable](#stream_class_stream_readable) stream, removing this [Writable](#stream_class_stream_writable) from its set of destinations. ```None const writer = getWritableStreamSomehow(); const reader = getReadableStreamSomehow(); writer.on('unpipe', (src) => { console.error('Something has stopped piping into th...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
456c1863-b3c4-51e8-afa9-e6b02dbab366
docs
nodejs
nodejs_stream
7x
14
implementations that implement the `writable._writev()` method can perform buffered writes in a more optimized manner. See also: [`writable.uncork()`](#stream_writable_uncork). ##### writable.end([chunk][, encoding][, callback])[#](#stream_writable_end_chunk_encoding_callback) Added in: v0.9.4 * `chunk` [<string>](...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
2cf70cba-8b7e-5fe4-a3e7-2e241a56dc5e
docs
nodejs
nodejs_stream
7x
15
Calling the `writable.end()` method signals that no more data will be written to the [Writable](#stream_class_stream_writable). The optional `chunk` and `encoding` arguments allow one final additional chunk of data to be written immediately before closing the stream. If provided, the optional `callback` function is att...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
f3f515e6-249e-5660-8a23-4b4c46f26eb0
docs
nodejs
nodejs_stream
7x
16
* `encoding` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) The new default encoding * Returns: `this` The `writable.setDefaultEncoding()` method sets the default `encoding` for a [Writable](#stream_class_stream_writable) stream. ##### writable.uncork()[#](#stream_writ...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
be022232-f663-5c2f-97b3-1f714224968d
docs
nodejs
nodejs_stream
7x
17
number of calls to `writable.uncork()` must be called to flush the buffered data. ```None stream.cork(); stream.write('some '); stream.cork(); stream.write('data '); process.nextTick(() => { stream.uncork(); // The data will not be flushed until uncork() is called a second time. stream.uncork(); }); ``` See als...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
6be9afd5-45ca-5ac8-8a31-1123672ec0d3
docs
nodejs
nodejs_stream
7x
18
* `callback` [<Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) Callback for when this chunk of data is flushed * Returns: [<boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type) `false` if the stream wishes for the calling c...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
2418cd72-539c-5bac-b174-2477d4acf467
docs
nodejs
nodejs_stream
7x
19
stop until the [`'drain'`](#stream_event_drain) event is emitted. While a stream is not draining, calls to `write()` will buffer `chunk`, and return false. Once all currently buffered chunks are drained (accepted for delivery by the operating system), the `'drain'` event will be emitted. It is recommended that once wr...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
07efbc37-af3a-5f1d-9f76-9ddb2e22e208
docs
nodejs
nodejs_stream
7x
20
problematic for a [Transform](#stream_class_stream_transform), because the `Transform` streams are paused by default until they are piped or an `'data'` or `'readable'` event handler is added. If the data to be written can be generated or fetched on demand, it is recommended to encapsulate the logic into a [Readable](...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
459e6ada-ca74-501e-a7d5-8641d9295cef
docs
nodejs
nodejs_stream
7x
21
### Readable Streams[#](#stream_readable_streams) Readable streams are an abstraction for a *source* from which data is consumed. Examples of Readable streams include: * [HTTP responses, on the client](http.html#http_class_http_incomingmessage) * [HTTP requests, on the server](http.html#http_class_http_incomingmessa...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
2f16f20c-44de-5c0a-9e72-46337f63b0f4
docs
nodejs
nodejs_stream
7x
22
[`EventEmitter`](events.html#events_class_eventemitter) interface. In paused mode, the [`stream.read()`](#stream_readable_read_size) method must be called explicitly to read chunks of data from the stream. All [Readable](#stream_class_stream_readable) streams begin in paused mode but can be switched to flowing mode i...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
a8372bf5-11d7-5ef5-9517-046addeb0a01
docs
nodejs
nodejs_stream
7x
23
The important concept to remember is that a Readable will not generate data until a mechanism for either consuming or ignoring that data is provided. If the consuming mechanism is disabled or taken away, the Readable will *attempt* to stop generating the data. *Note*: For backwards compatibility reasons, removing [`'d...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
9fdc675d-4d5b-5dfa-a337-da5c3e36714d
docs
nodejs
nodejs_stream
7x
24
#### Three States[#](#stream_three_states) The "two modes" of operation for a Readable stream are a simplified abstraction for the more complicated internal state management that is happening within the Readable stream implementation. Specifically, at any given point in time, every Readable is in one of three possibl...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
d6277ef7-34ca-52c4-b943-c00a383089a9
docs
nodejs
nodejs_stream
7x
25
temporarily halting the flowing of events but *not* halting the generation of data. While `readable._readableState.flowing` is `false`, data may be accumulating within the streams internal buffer. #### Choose One[#](#stream_choose_one) The Readable stream API evolved across multiple Node.js versions and provides mul...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
6a06f50c-0d82-52e7-a9d1-8268935cfe7e
docs
nodejs
nodejs_stream
7x
26
#### Class: stream.Readable[#](#stream_class_stream_readable) Added in: v0.9.4 ##### Event: 'close'[#](#stream_event_close_1) Added in: v0.9.4 The `'close'` event is emitted when the stream and any of its underlying resources (a file descriptor, for example) have been closed. The event indicates that no more events...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
fe6c87f1-54f5-547b-a3b5-b854b53f9054
docs
nodejs
nodejs_stream
7x
27
a chunk of data to a consumer. This may occur whenever the stream is switched in flowing mode by calling `readable.pipe()`, `readable.resume()`, or by attaching a listener callback to the `'data'` event. The `'data'` event will also be emitted whenever the `readable.read()` method is called and a chunk of data is avail...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
e3bd69e5-261c-5986-a50b-e33c131918dd
docs
nodejs
nodejs_stream
7x
28
##### Event: 'end'[#](#stream_event_end) Added in: v0.9.4 The `'end'` event is emitted when there is no more data to be consumed from the stream. *Note*: The `'end'` event **will not be emitted** unless the data is completely consumed. This can be accomplished by switching the stream into flowing mode, or by calling...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
6f6c39ed-2485-5624-8117-3920d82f695c
docs
nodejs
nodejs_stream
7x
29
due to an underlying internal failure, or when a stream implementation attempts to push an invalid chunk of data. The listener callback will be passed a single `Error` object. ##### Event: 'readable'[#](#stream_event_readable) Added in: v0.9.4 The `'readable'` event is emitted when there is data available to be rea...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
47c78fa4-8ed8-5e60-b8bb-66843069da62
docs
nodejs
nodejs_stream
7x
30
available data. In the latter case, [`stream.read()`](#stream_readable_read_size) will return `null`. For instance, in the following example, `foo.txt` is an empty file: ```None const fs = require('fs'); const rr = fs.createReadStream('foo.txt'); rr.on('readable', () => { console.log('readable:', rr.read()); }); rr....
large_dataset/raw/docs/nodejs/stream/stream_7x.md
ba0e70c8-2832-5edd-af2b-ea4419d6aa04
docs
nodejs
nodejs_stream
7x
31
const readable = new stream.Readable readable.isPaused() // === false readable.pause() readable.isPaused() // === true readable.resume() readable.isPaused() // === false ``` ##### readable.pause()[#](#stream_readable_pause) Added in: v0.9.4 * Returns: `this` The `readable.pause()` method will cause a stream in flo...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
6ef29ed9-185b-5ecd-9c49-54dfd1128223
docs
nodejs
nodejs_stream
7x
32
##### readable.pipe(destination[, options])[#](#stream_readable_pipe_destination_options) Added in: v0.9.4 * `destination` [<stream.Writable>](stream.html#stream_class_stream_writable) The destination for writing data * `options` [<Object>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Obje...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
bb3011f1-20b8-5675-9073-58aefb2e62de
docs
nodejs
nodejs_stream
7x
33
const readable = getReadableStreamSomehow(); const writable = fs.createWriteStream('file.txt'); // All the data from readable goes into 'file.txt' readable.pipe(writable); ``` It is possible to attach multiple Writable streams to a single Readable stream. The `readable.pipe()` method returns a reference to the *desti...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
1c29aeae-0f15-5367-ab4c-e8f6325fd6af
docs
nodejs
nodejs_stream
7x
34
writer.end('Goodbye\n'); }); ``` One important caveat is that if the Readable stream emits an error during processing, the Writable destination *is not closed* automatically. If an error occurs, it will be necessary to *manually* close each stream in order to prevent memory leaks. *Note*: The [`process.stderr`](pro...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
03863943-06c7-579b-940e-ffafeb85048b
docs
nodejs
nodejs_stream
7x
35
The `readable.read()` method pulls some data out of the internal buffer and returns it. If no data available to be read, `null` is returned. By default, the data will be returned as a `Buffer` object unless an encoding has been specified using the `readable.setEncoding()` method or the stream is operating in object mod...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
09fb90f3-1cd6-5e61-a097-5c7e6a0aa859
docs
nodejs
nodejs_stream
7x
36
var chunk; while (null !== (chunk = readable.read())) { console.log(`Received ${chunk.length} bytes of data.`); } }); ``` In general, it is recommended that developers avoid the use of the `'readable'` event and the `readable.read()` method in favor of using either `readable.pipe()` or the `'data'` event. A...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
69cfb018-0f2d-5e69-b081-41c490082251
docs
nodejs
nodejs_stream
7x
37
resume emitting [`'data'`](#stream_event_data) events, switching the stream into flowing mode. The `readable.resume()` method can be used to fully consume the data from a stream without actually processing any of that data as illustrated in the following example: ```None getReadableStreamSomehow() .resume() .on('...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
1406a680-d386-5f2a-811a-b96671566d05
docs
nodejs
nodejs_stream
7x
38
output data will 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. The Readable stream will properly handle multi-byte characters delivered through the stream that would otherwise become improperly decoded if simpl...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
c6ef340e-6c69-5461-9851-036df74b00dd
docs
nodejs
nodejs_stream
7x
39
The `readable.unpipe()` method detaches a Writable stream previously attached using the [`stream.pipe()`](#stream_readable_pipe_destination_options) method. If the `destination` is not specified, then *all* pipes are detached. If the `destination` is specified, but no pipe is set up for it, then the method does nothi...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
c86ec09c-e69e-5263-a895-55a83310f401
docs
nodejs
nodejs_stream
7x
40
The `readable.unshift()` method pushes a chunk of data back into the internal buffer. This is useful in certain situations where a stream is being consumed by code that needs to "un-consume" some amount of data that it has optimistically pulled out of the source, so that the data can be passed on to some other party. ...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
8f967d6b-5dab-5c42-abc4-c3ea6ccc8a36
docs
nodejs
nodejs_stream
7x
41
stream.on('readable', onReadable); const decoder = new StringDecoder('utf8'); var header = ''; function onReadable() { var chunk; while (null !== (chunk = stream.read())) { var str = decoder.write(chunk); if (str.match(/\n\n/)) { // found the header boundary var split = str.s...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
3bd67dbe-9938-5d63-b933-b8d7b1959350
docs
nodejs
nodejs_stream
7x
42
will not end the reading process by resetting the internal reading state of the stream. This can cause unexpected results if `readable.unshift()` is called during a read (i.e. from within a [`stream._read()`](#stream_readable_read_size_1) implementation on a custom stream). Following the call to `readable.unshift()` wi...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
86feac50-b503-533c-8375-8a474ae1357a
docs
nodejs
nodejs_stream
7x
43
When using an older Node.js library that emits [`'data'`](#stream_event_data) events and has a [`stream.pause()`](#stream_readable_pause) method that is advisory only, the `readable.wrap()` method can be used to create a [Readable](#stream_class_stream_readable) stream that uses the old stream as its data source. It w...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
cb57f0a1-6850-5d7e-aa36-160e70d1b251
docs
nodejs
nodejs_stream
7x
44
#### Class: stream.Duplex[#](#stream_class_stream_duplex) History | Version | Changes | | --- | --- | | v6.8.0 | Instances of `Duplex` now return `true` when checking `instanceof stream.Writable`. | | v0.9.4 | Added in: v0.9.4 | Duplex streams are streams that implement both the [Readable](#stream_class_stream_reada...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
c525c6e3-09fd-57f6-8286-df330e6275b9
docs
nodejs
nodejs_stream
7x
45
* [crypto streams](crypto.html) ## API for Stream Implementers[#](#stream_api_for_stream_implementers) The `stream` module API has been designed to make it possible to easily implement streams using JavaScript's prototypal inheritance model. First, a stream developer would declare a new JavaScript class that extends...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
6e77431e-1639-5809-92d2-f16750c00d2a
docs
nodejs
nodejs_stream
7x
46
| Reading and writing | [Duplex](#stream_class_stream_duplex) | `_read`, `_write`, `_writev` | | Operate on written data, then read the result | [Transform](#stream_class_stream_transform) | `_transform`, `_flush` | *Note*: The implementation code for a stream should *never* call the "public" methods of a stream that ...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
d0d79656-c7b1-586e-8381-e19c3e663757
docs
nodejs
nodejs_stream
7x
47
write(chunk, encoding, callback) { // ... } }); ``` ### Implementing a Writable Stream[#](#stream_implementing_a_writable_stream) The `stream.Writable` class is extended to implement a [Writable](#stream_class_stream_writable) stream. Custom Writable streams *must* call the `new stream.Writable([options])` c...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
802f103c-4979-58e4-b6b2-617b72743aac
docs
nodejs
nodejs_stream
7x
48
+ `decodeStrings` [<boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type) Whether or not to decode strings into Buffers before passing them to [`stream._write()`](#stream_writable_write_chunk_encoding_callback_1). Defaults to `true` + `objectMode` [<boolean>](https:...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
168057ff-91d8-5a9f-9b51-59543224e81f
docs
nodejs
nodejs_stream
7x
49
+ `writev` [<Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) Implementation for the [`stream._writev()`](#stream_writable_writev_chunks_callback) method. For example: ```None const Writable = require('stream').Writable; class MyWritable extends Writable { ...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
d2273071-bccf-5aae-a423-de3981d36aa7
docs
nodejs
nodejs_stream
7x
50
#### writable.\_write(chunk, encoding, callback)[#](#stream_writable_write_chunk_encoding_callback_1) * `chunk` [<Buffer>](buffer.html#buffer_class_buffer) | [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) | <any> The chunk to be written. Will **always** be a buffer un...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
23155d18-9d6e-56db-8370-6975b77f798d
docs
nodejs
nodejs_stream
7x
51
[`writable._write()`](#stream_writable_write_chunk_encoding_callback_1) method to send data to the underlying resource. *Note*: [Transform](#stream_class_stream_transform) streams provide their own implementation of the [`writable._write()`](#stream_writable_write_chunk_encoding_callback_1). *Note*: **This function M...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
35f8be54-0a14-5acb-8cda-e1a8e563fbd4
docs
nodejs
nodejs_stream
7x
52
emit a [`'drain'`](#stream_event_drain) event. If a stream implementation is capable of processing multiple chunks of data at once, the `writable._writev()` method should be implemented. If the `decodeStrings` property is set in the constructor options, then `chunk` may be a string rather than a Buffer, and `encoding`...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
4bd8b1c5-ea5e-52bf-958a-283219260303
docs
nodejs
nodejs_stream
7x
53
#### writable.\_writev(chunks, callback)[#](#stream_writable_writev_chunks_callback) * `chunks` [<Array>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) The chunks to be written. Each chunk has following format: `{ chunk: ..., encoding: ... }`. * `callback` [<Function>](https...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
6fd69f84-49aa-570b-9185-6005f2ae1eb3
docs
nodejs
nodejs_stream
7x
54
The `writable._writev()` method is prefixed with an underscore because it is internal to the class that defines it, and should never be called directly by user programs. #### Errors While Writing[#](#stream_errors_while_writing) It is recommended that errors occurring during the processing of the `writable._write()` ...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
3e9844f0-d32d-5e73-974f-3a03bddf6f9a
docs
nodejs
nodejs_stream
7x
55
#### An Example Writable Stream[#](#stream_an_example_writable_stream) The following illustrates a rather simplistic (and somewhat pointless) custom Writable stream implementation. While this specific Writable stream instance is not of any real particular usefulness, the example illustrates each of the required elemen...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
26f7b637-e066-52be-b7fe-7314eb3ece5d
docs
nodejs
nodejs_stream
7x
56
constructor and implement the `readable._read()` method. #### new stream.Readable([options])[#](#stream_new_stream_readable_options) * `options` [<Object>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) + `highWaterMark` [<number>](https://developer.mozilla.org/en-US/docs/W...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
13b96302-104e-5a71-94f5-95d704995dc4
docs
nodejs
nodejs_stream
7x
57
a single value instead of a Buffer of size n. Defaults to `false` + `read` [<Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) Implementation for the [`stream._read()`](#stream_readable_read_size_1) method. For example: ```None const Readable = require('st...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
9d0fdfbf-b585-57d0-a831-6e1e770d2856
docs
nodejs
nodejs_stream
7x
58
#### readable.\_read(size)[#](#stream_readable_read_size_1) * `size` [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) Number of bytes to read asynchronously *Note*: **This function MUST NOT be called by application code directly.** It should be implemented by child class...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
235713c5-75d8-5059-b830-f5e7113c523d
docs
nodejs
nodejs_stream
7x
59
*Note*: Once the `readable._read()` method has been called, it will not be called again until the [`readable.push()`](#stream_readable_push_chunk_encoding) method is called. The `size` argument is advisory. For implementations where a "read" is a single operation that returns data can use the `size` argument to determ...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
20484e36-7ca5-5e8b-90e9-2b490c9b4b7f
docs
nodejs
nodejs_stream
7x
60
* `chunk` [<Buffer>](buffer.html#buffer_class_buffer) | [<null>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Null_type) | [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) | <any> Chunk of data to push into the read queue * `encoding` [<string>](...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
2fdd7bdb-8761-5ce9-8676-658ef728e8c4
docs
nodejs
nodejs_stream
7x
61
`readable.push()` can be read out by calling the [`readable.read()`](#stream_readable_read_size) method when the [`'readable'`](#stream_event_readable) event is emitted. When the Readable is operating in flowing mode, the data added with `readable.push()` will be delivered by emitting a `'data'` event. The `readable....
large_dataset/raw/docs/nodejs/stream/stream_7x.md
56836bc9-864c-5007-a599-6ce9831a0db4
docs
nodejs
nodejs_stream
7x
62
this._source.ondata = (chunk) => { // if push() returns false, then stop reading from source if (!this.push(chunk)) this._source.readStop(); }; // When the source ends, push the EOF-signaling `null` chunk this._source.onend = () => { this.push(null); }; } // _read will...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
4f3f1e9e-9c97-5eaf-9789-95fa4eb00f8d
docs
nodejs
nodejs_stream
7x
63
operating in flowing or paused mode. Using the `'error'` event ensures consistent and predictable handling of errors. ```None const Readable = require('stream').Readable; const myReadable = new Readable({ read(size) { if (checkSomeErrorCondition()) { process.nextTick(() => this.emit('error', err)); ...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
c5ba16cf-7f93-5565-b4aa-2ccd504cda7a
docs
nodejs
nodejs_stream
7x
64
### Implementing a Duplex Stream[#](#stream_implementing_a_duplex_stream) A [Duplex](#stream_class_stream_duplex) stream is one that implements both [Readable](#stream_class_stream_readable) and [Writable](#stream_class_stream_writable), such as a TCP socket connection. Because JavaScript does not have support for mu...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
634d2fc6-91f9-5e7f-b5c9-2f60e465dc2b
docs
nodejs
nodejs_stream
7x
65
#### new stream.Duplex(options)[#](#stream_new_stream_duplex_options) * `options` [<Object>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) Passed to both Writable and Readable constructors. Also has the following fields: + `allowHalfOpen` [<boolean>](https://developer.moz...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
a0e9d529-e154-58ef-acc3-65b0887bf893
docs
nodejs
nodejs_stream
7x
66
For example: ```None const Duplex = require('stream').Duplex; class MyDuplex extends Duplex { constructor(options) { super(options); } } ``` Or, when using pre-ES6 style constructors: ```None const Duplex = require('stream').Duplex; const util = require('util'); function MyDuplex(options) { if (!(this in...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
90901fd3-5fa7-5eef-9285-7f5f72828272
docs
nodejs
nodejs_stream
7x
67
The following illustrates a simple example of a Duplex stream that buffers incoming written data via the [Writable](#stream_class_stream_writable) interface that is read back out via the [Readable](#stream_class_stream_readable) interface. ```None const Duplex = require('stream').Duplex; const kSource = Symbol('source...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
3d3dfae2-827e-53ed-bae6-5930690cc40e
docs
nodejs
nodejs_stream
7x
68
#### Object Mode Duplex Streams[#](#stream_object_mode_duplex_streams) For Duplex streams, `objectMode` can be set exclusively for either the Readable or Writable side using the `readableObjectMode` and `writableObjectMode` options respectively. In the following example, for instance, a new Transform stream (which is...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
e33489e0-13bc-5f6f-bdf3-92a881f8d6a2
docs
nodejs
nodejs_stream
7x
69
myTransform.setEncoding('ascii'); myTransform.on('data', (chunk) => console.log(chunk)); myTransform.write(1); // Prints: 01 myTransform.write(10); // Prints: 0a myTransform.write(100); // Prints: 64 ``` ### Implementing a Transform Stream[#](#stream_implementing_a_transform_stream) A [Transform](#stream_class_strea...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
6752a141-9c38-53d3-b67f-5ad213c8e0a6
docs
nodejs
nodejs_stream
7x
70
The `stream.Transform` class prototypically inherits from `stream.Duplex` and implements its own versions of the `writable._write()` and `readable._read()` methods. Custom Transform implementations *must* implement the [`transform._transform()`](#stream_transform_transform_chunk_encoding_callback) method and *may* also...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
f4e3a6a9-0310-5433-a133-e84f87b5dabd
docs
nodejs
nodejs_stream
7x
71
[`stream._transform()`](#stream_transform_transform_chunk_encoding_callback) method. + `flush` [<Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) Implementation for the [`stream._flush()`](#stream_transform_flush_callback) method. For example: ```None con...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
3f94e4a0-c7ba-5915-89dc-0a44ed011bda
docs
nodejs
nodejs_stream
7x
72
#### Events: 'finish' and 'end'[#](#stream_events_finish_and_end) The [`'finish'`](#stream_event_finish) and [`'end'`](#stream_event_end) events are from the `stream.Writable` and `stream.Readable` classes, respectively. The `'finish'` event is emitted after [`stream.end()`](#stream_writable_end_chunk_encoding_callbac...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
88d3615b-8a88-5ccf-9b60-ce9af04d7770
docs
nodejs
nodejs_stream
7x
73
should be implemented by child classes, and called only by the internal Readable class methods only. In some cases, a transform operation may need to emit an additional bit of data at the end of the stream. For example, a `zlib` compression stream will store an amount of internal state used to optimally compress the o...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
2fb35660-266d-5af7-b83d-af39bb1627cc
docs
nodejs
nodejs_stream
7x
74
The `transform._flush()` method is prefixed with an underscore because it is internal to the class that defines it, and should never be called directly by user programs. #### transform.\_transform(chunk, encoding, callback)[#](#stream_transform_transform_chunk_encoding_callback) * `chunk` [<Buffer>](buffer.html#buffe...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
9d96de1c-29d1-5b76-8396-92e18043c72a
docs
nodejs
nodejs_stream
7x
75
argument and data) to be called after the supplied `chunk` has been processed. *Note*: **This function MUST NOT be called by application code directly.** It should be implemented by child classes, and called only by the internal Readable class methods only. All Transform stream implementations must provide a `_tr...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
0efa012d-df71-5b91-bb7e-be5febe38cd4
docs
nodejs
nodejs_stream
7x
76
if an error occurred while processing the input or `null` otherwise. If a second argument is passed to the `callback`, it will be forwarded on to the `readable.push()` method. In other words the following are equivalent: ```None transform.prototype._transform = function (data, encoding, callback) { this.push(data); ...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
dd27fa57-b4ef-51bd-87fc-64c67867a967
docs
nodejs
nodejs_stream
7x
77
## Additional Notes[#](#stream_additional_notes) ### Compatibility with Older Node.js Versions[#](#stream_compatibility_with_older_node_js_versions) In versions of Node.js prior to v0.10, the Readable stream interface was simpler, but also less powerful and less useful. * Rather than waiting for calls the [`stream.r...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
036ccc09-9d8d-5ebb-a1b2-f730d9574bec
docs
nodejs
nodejs_stream
7x
78
with older Node.js programs, Readable streams switch into "flowing mode" when a [`'data'`](#stream_event_data) event handler is added, or when the [`stream.resume()`](#stream_readable_resume) method is called. The effect is that, even when not using the new [`stream.read()`](#stream_readable_read_size) method and [`'re...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
143e3c3d-2cd6-5a43-b257-62314350d6aa
docs
nodejs
nodejs_stream
7x
79
socket.end('The message was received but was not processed.\n'); }); }).listen(1337); ``` In versions of Node.js prior to v0.10, the incoming message data would be simply discarded. However, in Node.js v0.10 and beyond, the socket remains paused forever. The workaround in this situation is to call the [`stream...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
2f8756c2-e51c-506d-a67e-fb2e9e6d7b60
docs
nodejs
nodejs_stream
7x
80
### `readable.read(0)`[#](#stream_readable_read_0) There are some cases where it is necessary to trigger a refresh of the underlying readable stream mechanisms, without actually consuming any data. In such cases, it is possible to call `readable.read(0)`, which will always return `null`. If the internal read buffer i...
large_dataset/raw/docs/nodejs/stream/stream_7x.md
e8cd8c0c-ae17-50b6-9f0e-36ac444e33a8
docs
nodejs
nodejs_stream
7x
81
However, because the argument is an empty string, no data is added to the readable buffer so there is nothing for a user to consume.
large_dataset/raw/docs/nodejs/stream/stream_7x.md
385a9da0-71df-504f-80e1-f5c9859eec4c
docs
nodejs
nodejs_stream
8x
0
# Stream# Source: https://nodejs.org/docs/latest-v8.x/api/stream.html Version: 8.x [Stability: 2](documentation.html#documentation_stability_index) - Stable A stream is an abstract interface for working with streaming data in Node.js. The `stream` module provides a base API that makes it easy to build objects that i...
large_dataset/raw/docs/nodejs/stream/stream_8x.md
649bd424-e94e-5425-b498-61b3c50354aa
docs
nodejs
nodejs_stream
8x
1
Developers who are primarily *consuming* stream objects will rarely need to use the `stream` module directly. ## Organization of this Document[#](#stream_organization_of_this_document) This document is divided into two primary sections with a third section for additional notes. The first section explains the elements...
large_dataset/raw/docs/nodejs/stream/stream_8x.md
7f17bc09-2d21-5d8f-b1e3-23300d4427e4
docs
nodejs
nodejs_stream
8x
2
* [Duplex](#stream_class_stream_duplex) - streams that are both Readable and Writable (for example [`net.Socket`](net.html#net_class_net_socket)). * [Transform](#stream_class_stream_transform) - Duplex streams that can modify or transform the data as it is written and read (for example [`zlib.createDeflate()`](zlib...
large_dataset/raw/docs/nodejs/stream/stream_8x.md
f68c9d21-b22a-568e-8077-e61d26b3e992
docs
nodejs
nodejs_stream
8x
3
### Buffering[#](#stream_buffering) Both [Writable](#stream_class_stream_writable) and [Readable](#stream_class_stream_readable) streams will store data in an internal buffer that can be retrieved using `writable._writableState.getBuffer()` or `readable._readableState.buffer`, respectively. The amount of data potenti...
large_dataset/raw/docs/nodejs/stream/stream_8x.md
09779a12-990e-5042-b717-595bd9f595e8
docs
nodejs
nodejs_stream
8x
4
by `highWaterMark`, the stream will temporarily stop reading data from the underlying resource until the data currently buffered can be consumed (that is, the stream will stop calling the internal `readable._read()` method that is used to fill the read buffer). Data is buffered in Writable streams when the [`writable....
large_dataset/raw/docs/nodejs/stream/stream_8x.md
730ae99b-cf91-5ea1-bb78-cca9815d9d1f
docs
nodejs
nodejs_stream
8x
5
Because [Duplex](#stream_class_stream_duplex) and [Transform](#stream_class_stream_transform) streams are both Readable and Writable, each maintain *two* separate internal buffers used for reading and writing, allowing each side to operate independently of the other while maintaining an appropriate and efficient flow o...
large_dataset/raw/docs/nodejs/stream/stream_8x.md
534dfa14-f0a4-54a7-8f0e-735f0d35500f
docs
nodejs
nodejs_stream
8x
6
const http = require('http'); const server = http.createServer((req, res) => { // req is an http.IncomingMessage, which is a Readable Stream // res is an http.ServerResponse, which is a Writable Stream let body = ''; // Get the data as utf8 strings. // If an encoding is not set, Buffer objects will be recei...
large_dataset/raw/docs/nodejs/stream/stream_8x.md
c8ae6b01-e5d1-5c6e-b660-9d84005900ba
docs
nodejs
nodejs_stream
8x
7
// error: Unexpected token o in JSON at position 1 ``` [Writable](#stream_class_stream_writable) streams (such as `res` in the example) expose methods such as `write()` and `end()` that are used to write data onto the stream. [Readable](#stream_class_stream_readable) streams use the [`EventEmitter`](events.html#event...
large_dataset/raw/docs/nodejs/stream/stream_8x.md
658e0cd5-d5ee-550f-8d2a-3be96ece5210
docs
nodejs
nodejs_stream
8x
8
are not required to implement the stream interfaces directly and will generally have no reason to call `require('stream')`. Developers wishing to implement new types of streams should refer to the section [API for Stream Implementers](#stream_api_for_stream_implementers). ### Writable Streams[#](#stream_writable_stre...
large_dataset/raw/docs/nodejs/stream/stream_8x.md
f4a141e4-0d21-5683-bf31-f566ce880e19
docs
nodejs
nodejs_stream
8x
9
*Note*: Some of these examples are actually [Duplex](#stream_class_stream_duplex) streams that implement the [Writable](#stream_class_stream_writable) interface. All [Writable](#stream_class_stream_writable) streams implement the interface defined by the `stream.Writable` class. While specific instances of [Writable]...
large_dataset/raw/docs/nodejs/stream/stream_8x.md
6f75a244-f557-5749-a1b4-464d94affd48
docs
nodejs
nodejs_stream
8x
10
Not all Writable streams will emit the `'close'` event. ##### Event: 'drain'[#](#stream_event_drain) Added in: v0.9.4 If a call to [`stream.write(chunk)`](#stream_writable_write_chunk_encoding_callback) returns `false`, the `'drain'` event will be emitted when it is appropriate to resume writing data to the stream. ...
large_dataset/raw/docs/nodejs/stream/stream_8x.md
81ba0362-a25c-5d5a-a27f-86e7902f375d
docs
nodejs
nodejs_stream
8x
11
##### Event: 'error'[#](#stream_event_error) Added in: v0.9.4 * [<Error>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) The `'error'` event is emitted if an error occurred while writing or piping data. The listener callback is passed a single `Error` argument when called. *...
large_dataset/raw/docs/nodejs/stream/stream_8x.md
2a91adf2-d1d1-5728-a8ee-d3b1b6aa9bcc
docs
nodejs
nodejs_stream
8x
12
##### Event: 'pipe'[#](#stream_event_pipe) Added in: v0.9.4 * `src` [<stream.Readable>](stream.html#stream_class_stream_readable) source stream that is piping to this writable The `'pipe'` event is emitted when the [`stream.pipe()`](#stream_readable_pipe_destination_options) method is called on a readable stream, ad...
large_dataset/raw/docs/nodejs/stream/stream_8x.md
11e2ae9a-c8dc-5c30-b1bb-24c61ba728ef
docs
nodejs
nodejs_stream
8x
13
on a [Readable](#stream_class_stream_readable) stream, removing this [Writable](#stream_class_stream_writable) from its set of destinations. This is also emitted in case this [Writable](#stream_class_stream_writable) stream emits an error when a [Readable](#stream_class_stream_readable) stream pipes into it. ```None ...
large_dataset/raw/docs/nodejs/stream/stream_8x.md
34f8fc4a-4c70-5ef4-8703-8b89382dccef
docs
nodejs
nodejs_stream
8x
14
many small chunks of data to a stream do not cause a backup in the internal buffer that would have an adverse impact on performance. In such situations, implementations that implement the `writable._writev()` method can perform buffered writes in a more optimized manner. See also: [`writable.uncork()`](#stream_writabl...
large_dataset/raw/docs/nodejs/stream/stream_8x.md