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
8d2416a0-a1e5-5a64-a567-84f8902e38be
docs
nodejs
nodejs_stream
10x
27
then calling [`stream.pause()`](#stream_readable_pause) will not guarantee that the stream will *remain* paused once those destinations drain and ask for more data. If a [`Readable`](#stream_class_stream_readable) is switched into flowing mode and there are no consumers available to handle the data, that data will be ...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
cc1dc110-e4b3-5bf8-9179-9ce6dfb233f1
docs
nodejs
nodejs_stream
10x
28
#### 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 p...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
6f23ce70-a565-51d6-ab46-4e7719789bad
docs
nodejs
nodejs_stream
10x
29
temporarily halting the flowing of events but *not* halting the generation of data. While in this state, attaching a listener for the `'data'` event will not switch `readable.readableFlowing` to `true`. ```None const { PassThrough, Writable } = require('stream'); const pass = new PassThrough(); const writable = new Wr...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
4752a588-2bf5-5c15-98a2-110811f80eea
docs
nodejs
nodejs_stream
10x
30
to consume data from a single stream. Specifically, using a combination of `on('data')`, `on('readable')`, `pipe()`, or async iterators could lead to unintuitive behavior. Use of the `readable.pipe()` method is recommended for most users as it has been implemented to provide the easiest way of consuming stream data. D...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
57a7dbc8-9e29-5d76-8155-7df05a4341eb
docs
nodejs
nodejs_stream
10x
31
that no more events will be emitted, and no further computation will occur. A [`Readable`](#stream_class_stream_readable) stream will always emit the `'close'` event if it is created with the `emitClose` option. ##### Event: 'data'[#](#stream_event_data) Added in: v0.9.4 * `chunk` [<Buffer>](buffer.html#buffer_clas...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
dfab5e2c-6e3f-51cb-a0fb-a3f59992f247
docs
nodejs
nodejs_stream
10x
32
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 available to be returned. Attaching a `'data'` event listener to a stream that has not been explicitly paused will switch the stream into flowing mode. Dat...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
1823f061-84cc-5023-bde9-3c5a107232f9
docs
nodejs
nodejs_stream
10x
33
consumed. This can be accomplished by switching the stream into flowing mode, or by calling [`stream.read()`](#stream_readable_read_size) repeatedly until all data has been consumed. ```None const readable = getReadableStreamSomehow(); readable.on('data', (chunk) => { console.log(`Received ${chunk.length} bytes of d...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
3bcb0dca-3f4b-56f7-949f-5578eee02cf6
docs
nodejs
nodejs_stream
10x
34
##### Event: 'readable'[#](#stream_event_readable) History | Version | Changes | | --- | --- | | v10.0.0 | The `'readable'` is always emitted in the next tick after `.push()` is called | | v10.0.0 | Using `'readable'` requires calling `.read()`. | | v0.9.4 | Added in: v0.9.4 | The `'readable'` event is emitted when ...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
07095d9e-9321-5b8d-b9ce-f6ef10277cee
docs
nodejs
nodejs_stream
10x
35
reached. In the former case, [`stream.read()`](#stream_readable_read_size) will return the 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.createRead...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
f44335e3-01e1-5b27-83bf-bb07813c6847
docs
nodejs
nodejs_stream
10x
36
If there are `'data'` listeners when `'readable'` is removed, the stream will start flowing, i.e. `'data'` events will be emitted without calling `.resume()`. ##### readable.destroy([error])[#](#stream_readable_destroy_error) Added in: v8.0.0 * `error` [<Error>](https://developer.mozilla.org/en-US/docs/Web/JavaScrip...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
882d8ff3-0948-5c75-b5b1-baf9f0132c34
docs
nodejs
nodejs_stream
10x
37
##### readable.isPaused()[#](#stream_readable_ispaused) Added in: v0.11.14 * Returns: [<boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type) The `readable.isPaused()` method returns the current operating state of the `Readable`. This is used primarily by the mechanism that ...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
3d279c12-eb9f-5169-bb7c-cb32f3ba6546
docs
nodejs
nodejs_stream
10x
38
```None const readable = getReadableStreamSomehow(); readable.on('data', (chunk) => { console.log(`Received ${chunk.length} bytes of data.`); readable.pause(); console.log('There will be no additional data for 1 second.'); setTimeout(() => { console.log('Now data will start flowing again.'); readable.re...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
9d659807-0138-5c48-a629-cf1b1bf18cbc
docs
nodejs
nodejs_stream
10x
39
* Returns: [<stream.Writable>](stream.html#stream_class_stream_writable) The *destination*, allowing for a chain of pipes if it is a [`Duplex`](#stream_class_stream_duplex) or a [`Transform`](#stream_class_stream_transform) stream The `readable.pipe()` method attaches a [`Writable`](#stream_class_stream_writable) st...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
b396594e-8a71-5dbc-9f4f-bd013f67701a
docs
nodejs
nodejs_stream
10x
40
The `readable.pipe()` method returns a reference to the *destination* stream making it possible to set up chains of piped streams: ```None const fs = require('fs'); const r = fs.createReadStream('file.txt'); const z = zlib.createGzip(); const w = fs.createWriteStream('file.txt.gz'); r.pipe(z).pipe(w); ``` By default,...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
55413d22-8d52-5ca6-a43a-a6619cc1cd1b
docs
nodejs
nodejs_stream
10x
41
to prevent memory leaks. The [`process.stderr`](process.html#process_process_stderr) and [`process.stdout`](process.html#process_process_stdout) `Writable` streams are never closed until the Node.js process exits, regardless of the specified options. ##### readable.read([size])[#](#stream_readable_read_size) Added i...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
94f8f328-9f2a-5cce-808d-818b1e4687e4
docs
nodejs
nodejs_stream
10x
42
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 mode. The optional `size` argument specifies a specific number of bytes to read. If `size` bytes are not available to be read, `null` will be returned *unl...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
52c353ed-5004-52e9-b55e-9b80d6decb28
docs
nodejs
nodejs_stream
10x
43
Note that the `while` loop is necessary when processing data with `readable.read()`. Only after `readable.read()` returns `null`, `'readable'` will be emitted. A `Readable` stream in object mode will always return a single item from a call to [`readable.read(size)`](#stream_readable_read_size), regardless of the value...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
6923c783-9c79-54bd-9a0a-34ad25f4c4f0
docs
nodejs
nodejs_stream
10x
44
##### readable.readableFlowing[#](#stream_readable_readableflowing) Added in: v9.4.0 * [<boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type) This property reflects the current state of a `Readable` stream as described in the [Stream Three States](#stream_three_states) sect...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
c693d366-0371-5a47-9e5a-5ecdd9ae652e
docs
nodejs
nodejs_stream
10x
45
##### readable.resume()[#](#stream_readable_resume) History | Version | Changes | | --- | --- | | v10.0.0 | The `resume()` has no effect if there is a `'readable'` event listening. | | v0.9.4 | Added in: v0.9.4 | * Returns: [<this>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this) T...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
e4d0db93-4705-5d28-b6e1-1da8d2554ad3
docs
nodejs
nodejs_stream
10x
46
##### readable.setEncoding(encoding)[#](#stream_readable_setencoding_encoding) Added in: v0.9.4 * `encoding` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) The encoding to use. * Returns: [<this>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operat...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
682835fc-ed42-5546-8ac8-54f7241efeeb
docs
nodejs
nodejs_stream
10x
47
through the stream that would otherwise become improperly decoded if simply pulled from the stream as `Buffer` objects. ```None const readable = getReadableStreamSomehow(); readable.setEncoding('utf8'); readable.on('data', (chunk) => { assert.equal(typeof chunk, 'string'); console.log('Got %d characters of string ...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
ed66b710-4d7d-5ead-ba05-20b4c26a2ea0
docs
nodejs
nodejs_stream
10x
48
const readable = getReadableStreamSomehow(); const writable = fs.createWriteStream('file.txt'); // All the data from readable goes into 'file.txt', // but only for the first second readable.pipe(writable); setTimeout(() => { console.log('Stop writing to file.txt.'); readable.unpipe(writable); console.log('Manuall...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
de7794ca-8958-594d-af84-f17db7219894
docs
nodejs
nodejs_stream
10x
49
read queue. For streams not operating in object mode, `chunk` must be a string, `Buffer` or `Uint8Array`. For object mode streams, `chunk` may be any JavaScript value other than `null`. The `readable.unshift()` method pushes a chunk of data back into the internal buffer. This is useful in certain situations wher...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
ba037dc0-5873-5a03-a8b1-bc45d8e63f9a
docs
nodejs
nodejs_stream
10x
50
// Call the callback with (error, header, stream) const { StringDecoder } = require('string_decoder'); function parseHeader(stream, callback) { stream.on('error', callback); stream.on('readable', onReadable); const decoder = new StringDecoder('utf8'); let header = ''; function onReadable() { let chunk; ...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
3c8443a7-40ac-53c0-b748-43a9df24936c
docs
nodejs
nodejs_stream
10x
51
header += str; } } } } ``` Unlike [`stream.push(chunk)`](#stream_readable_push_chunk_encoding), `stream.unshift(chunk)` 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. fro...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
a0b555c4-e285-51c7-bd38-e4fe4896e5ef
docs
nodejs
nodejs_stream
10x
52
Prior to Node.js 0.10, streams did not implement the entire `stream` module API as it is currently defined. (See [Compatibility](#stream_compatibility_with_older_node_js_versions) for more information.) When using an older Node.js library that emits [`'data'`](#stream_event_data) events and has a [`stream.pause()`](#s...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
164680ef-6984-5fe3-a771-89e4c4bc54d5
docs
nodejs
nodejs_stream
10x
53
##### readable[Symbol.asyncIterator]()[#](#stream_readable_symbol_asynciterator) History | Version | Changes | | --- | --- | | v10.17.0 | Symbol.asyncIterator support is no longer experimental. | | v10.0.0 | Added in: v10.0.0 | [Stability: 2](documentation.html#documentation_stability_index) - Stable * Returns: [<A...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
2874f097-1d56-511b-b314-9522b79da772
docs
nodejs
nodejs_stream
10x
54
has less then 64kb of data because no `highWaterMark` option is provided to [`fs.createReadStream()`](fs.html#fs_fs_createreadstream_path_options). ### Duplex and Transform Streams[#](#stream_duplex_and_transform_streams) #### Class: stream.Duplex[#](#stream_class_stream_duplex) History | Version | Changes | | --- ...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
27a015b5-9871-590d-a1f8-4b6e88b21df2
docs
nodejs
nodejs_stream
10x
55
related to the input. Like all [`Duplex`](#stream_class_stream_duplex) streams, `Transform` streams implement both the [`Readable`](#stream_class_stream_readable) and [`Writable`](#stream_class_stream_writable) interfaces. Examples of `Transform` streams include: * [zlib streams](zlib.html) * [crypto streams](crypto....
large_dataset/raw/docs/nodejs/stream/stream_10x.md
06793c7d-b294-5bb7-805f-e445c928ef47
docs
nodejs
nodejs_stream
10x
56
### stream.finished(stream, callback)[#](#stream_stream_finished_stream_callback) Added in: v10.0.0 * `stream` [<Stream>](stream.html#stream_stream) A readable and/or writable stream. * `callback` [<Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) A callback functi...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
e177db1e-b459-59e5-9036-c72d69cc82d8
docs
nodejs
nodejs_stream
10x
57
const finished = util.promisify(stream.finished); const rs = fs.createReadStream('archive.tar'); async function run() { await finished(rs); console.log('Stream is done reading.'); } run().catch(console.error); rs.resume(); // drain the stream ``` ### stream.pipeline(...streams[, callback])[#](#stream_stream_pip...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
1453f914-230a-537b-8094-7295520b58e1
docs
nodejs
nodejs_stream
10x
58
// A pipeline to gzip a potentially huge tar file efficiently: pipeline( fs.createReadStream('archive.tar'), zlib.createGzip(), fs.createWriteStream('archive.tar.gz'), (err) => { if (err) { console.error('Pipeline failed.', err); } else { console.log('Pipeline succeeded.'); } } ); ```...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
b8fcd06d-2f90-592c-b98a-71932b78eb72
docs
nodejs
nodejs_stream
10x
59
* `options` [<Object>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) Options provided to `new stream.Readable([options])`. By default, `Readable.from()` will set `options.objectMode` to `true`, unless this is explicitly opted out by setting `options.objectMode` to `false`....
large_dataset/raw/docs/nodejs/stream/stream_10x.md
51c72079-0694-596c-aebb-817b675fe437
docs
nodejs
nodejs_stream
10x
60
`stream.Duplex`, or `stream.Transform`), making sure they call the appropriate parent class constructor: ```None const { Writable } = require('stream'); class MyWritable extends Writable { constructor(options) { super(options); // ... } } ``` The new stream class must then implement one or more specific ...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
efe15fee-662e-5990-a4cd-29f1f9d1f387
docs
nodejs
nodejs_stream
10x
61
of a stream that are intended for use by consumers (as described in the [API for Stream Consumers](#stream_api_for_stream_consumers) section). Doing so may lead to adverse side effects in application code consuming the stream. ### Simplified Construction[#](#stream_simplified_construction) Added in: v1.2.0 For many ...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
e9c8be38-14f0-5f1d-8faa-3831986c8775
docs
nodejs
nodejs_stream
10x
62
constructor and implement the `writable._write()` method. The `writable._writev()` method *may* also be implemented. #### Constructor: new stream.Writable([options])[#](#stream_constructor_new_stream_writable_options) History | Version | Changes | | --- | --- | | v10.16.0 | Add `autoDestroy` option to automatically ...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
96ba89fa-db88-508b-87ad-321794adce9e
docs
nodejs
nodejs_stream
10x
63
+ `decodeStrings` [<boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type) Whether to encode `string`s passed to [`stream.write()`](#stream_writable_write_chunk_encoding_callback) to `Buffer`s (with the encoding specified in the [`stream.write()`](#stream_writable_writ...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
851f2704-e832-5a88-a73f-711f3ac4c309
docs
nodejs
nodejs_stream
10x
64
+ `objectMode` [<boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type) Whether or not the [`stream.write(anyObj)`](#stream_writable_write_chunk_encoding_callback) is a valid operation. When set, it becomes possible to write JavaScript values other than string, `Bu...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
53af0235-f3f6-59e7-bcaa-51dcb07c3396
docs
nodejs
nodejs_stream
10x
65
[`stream._writev()`](#stream_writable_writev_chunks_callback) method. + `destroy` [<Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) Implementation for the [`stream._destroy()`](#stream_writable_destroy_err_callback) method. + `final` [<Function>](https:/...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
3e94266a-5936-53db-8d0d-478f2b392992
docs
nodejs
nodejs_stream
10x
66
const util = require('util'); function MyWritable(options) { if (!(this instanceof MyWritable)) return new MyWritable(options); Writable.call(this, options); } util.inherits(MyWritable, Writable); ``` Or, using the Simplified Constructor approach: ```None const { Writable } = require('stream'); const myWrit...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
830dda28-5b8c-5bc6-8bba-9ac4017305df
docs
nodejs
nodejs_stream
10x
67
`decodeStrings` option is `false` or the stream is operating in object mode, the chunk will not be converted & will be whatever was passed to [`stream.write()`](#stream_writable_write_chunk_encoding_callback). * `encoding` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_t...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
5427b84c-f707-532f-88c1-5428ee8eb72b
docs
nodejs
nodejs_stream
10x
68
[`writable._write()`](#stream_writable_write_chunk_encoding_callback_1). This function MUST NOT be called by application code directly. It should be implemented by child classes, and called by the internal `Writable` class methods only. The `callback` method must be called to signal either that the write completed su...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
6a332ba6-6586-5431-b2f9-2d115a28fbec
docs
nodejs
nodejs_stream
10x
69
options, then `chunk` will remain the same object that is passed to `.write()`, and may be a string rather than a `Buffer`. This is to support implementations that have an optimized handling for certain string data encodings. In that case, the `encoding` argument will indicate the character encoding of the string. Othe...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
8b4a84a1-e443-5260-a80d-93c8bc23aa4c
docs
nodejs
nodejs_stream
10x
70
argument) to be invoked when processing is complete for the supplied chunks. This function MUST NOT be called by application code directly. It should be implemented by child classes, and called by the internal `Writable` class methods only. The `writable._writev()` method may be implemented in addition to `writable...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
512db04d-bfc2-573b-aefb-d8adf97854f9
docs
nodejs
nodejs_stream
10x
71
* `callback` [<Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) A callback function that takes an optional error argument. The `_destroy()` method is called by [`writable.destroy()`](#stream_writable_destroy_error). It can be overridden by child classes but it **m...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
1d6ae18a-e051-5938-87f3-9b16d300faac
docs
nodejs
nodejs_stream
10x
72
#### Errors While Writing[#](#stream_errors_while_writing) It is recommended that errors occurring during the processing of the `writable._write()` and `writable._writev()` methods are reported by invoking the callback and passing the error as the first argument. This will cause an `'error'` event to be emitted by th...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
7d1eddb7-06d2-5df4-88cf-2c0be1c76bf0
docs
nodejs
nodejs_stream
10x
73
#### 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 el...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
735804c7-ef54-5539-9a32-a9f5d4f6fd15
docs
nodejs
nodejs_stream
10x
74
multi-byte strings using `StringDecoder` and [`Writable`](#stream_class_stream_writable). ```None const { Writable } = require('stream'); const { StringDecoder } = require('string_decoder'); class StringWritable extends Writable { constructor(options) { super(options); this._decoder = new StringDecoder(opti...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
9b72784b-3d2c-5cca-8d8c-708033559570
docs
nodejs
nodejs_stream
10x
75
### Implementing a Readable Stream[#](#stream_implementing_a_readable_stream) The `stream.Readable` class is extended to implement a [`Readable`](#stream_class_stream_readable) stream. Custom `Readable` streams *must* call the `new stream.Readable([options])` constructor and implement the `readable._read()` method. ...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
f76f19b2-5d4e-5764-b54a-3dbc99b1f3f3
docs
nodejs
nodejs_stream
10x
76
**Default:** `16384` (16kb), or `16` for `objectMode` streams. + `encoding` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) If specified, then buffers will be decoded to strings using the specified encoding. **Default:** `null`. + `objectMode` [<boolean>](http...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
b7980f5b-a1cc-5b93-a02a-240926a5f7ca
docs
nodejs
nodejs_stream
10x
77
+ `autoDestroy` [<boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type) Whether this stream should automatically call `.destroy()` on itself after ending. **Default:** `false`. ```None const { Readable } = require('stream'); class MyReadable extends Readable { constru...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
86b5ecf2-89c4-58c6-a1ea-4c45395746aa
docs
nodejs
nodejs_stream
10x
78
#### readable.\_read(size)[#](#stream_readable_read_size_1) History | Version | Changes | | --- | --- | | v10.0.0 | call `_read()` only once per microtick | | v0.9.4 | Added in: v0.9.4 | * `size` [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) Number of bytes to read a...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
42446f6b-f942-5a50-8ae6-5d9873f53f9b
docs
nodejs
nodejs_stream
10x
79
when `_read()` is called again after it has stopped should it resume pushing additional data onto the queue. 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. `readable._read()` is guaranteed to be calle...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
dfcc5685-b434-5834-b36b-ffc6fd9c0c0f
docs
nodejs
nodejs_stream
10x
80
#### readable.\_destroy(err, callback)[#](#stream_readable_destroy_err_callback) Added in: v8.0.0 * `err` [<Error>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) A possible error. * `callback` [<Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Glob...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
8e14662e-4251-57e1-aa31-81df5dc287c1
docs
nodejs
nodejs_stream
10x
81
* `chunk` [<Buffer>](buffer.html#buffer_class_buffer) | [<Uint8Array>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) | [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) | [<null>](https://developer.mozilla.org/en-US/docs/Web/Ja...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
e3c3ef33-7c2d-549e-a043-f4d82e9a24f9
docs
nodejs
nodejs_stream
10x
82
pushed; `false` otherwise. When `chunk` is a `Buffer`, `Uint8Array` or `string`, the `chunk` of data will be added to the internal queue for users of the stream to consume. Passing `chunk` as `null` signals the end of the stream (EOF), after which no more data can be written. When the `Readable` is operating in pau...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
24808e98-9d6e-5a08-96d9-daf45bef33fe
docs
nodejs
nodejs_stream
10x
83
// and an `ondata` member that gets called when it has data, and // an `onend` member that gets called when the data is over. class SourceWrapper extends Readable { constructor(options) { super(options); this._source = getLowlevelSourceObject(); // Every time there's data, push it into the internal buf...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
fe474c93-0901-5a63-8708-4e9ee612a94d
docs
nodejs
nodejs_stream
10x
84
`readable.push()` is `undefined`, it will be treated as empty string or buffer. See [`readable.push('')`](#stream_readable_push) for more information. #### Errors While Reading[#](#stream_errors_while_reading) It is recommended that errors occurring during the processing of the `readable._read()` method are emitted u...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
3bcd97f3-8d30-531f-b391-7701a4bf9a38
docs
nodejs
nodejs_stream
10x
85
#### An Example Counting Stream[#](#stream_an_example_counting_stream) The following is a basic example of a `Readable` stream that emits the numerals from 1 to 1,000,000 in ascending order, and then ends. ```None const { Readable } = require('stream'); class Counter extends Readable { constructor(opt) { super...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
5b954621-60d8-538f-9d49-19c5deb419c3
docs
nodejs
nodejs_stream
10x
86
`stream.Duplex` class is extended to implement a [`Duplex`](#stream_class_stream_duplex) stream (as opposed to extending the `stream.Readable` *and* `stream.Writable` classes). The `stream.Duplex` class prototypically inherits from `stream.Readable` and parasitically from `stream.Writable`, but `instanceof` will work ...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
8256b45a-ca68-5134-80e4-6d77be4c1e62
docs
nodejs
nodejs_stream
10x
87
* `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.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type) I...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
e8cb878b-61fa-5dd4-9598-8002e16f1315
docs
nodejs
nodejs_stream
10x
88
+ `readableHighWaterMark` [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) Sets `highWaterMark` for the readable side of the stream. Has no effect if `highWaterMark` is provided. + `writableHighWaterMark` [<number>](https://developer.mozilla.org/en-US/docs/Web/Java...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
00036605-fa1f-51d8-8c73-d1df43deb193
docs
nodejs
nodejs_stream
10x
89
read(size) { // ... }, write(chunk, encoding, callback) { // ... } }); ``` #### An Example Duplex Stream[#](#stream_an_example_duplex_stream) The following illustrates a simple example of a `Duplex` stream that wraps a hypothetical lower-level source object to which data can be written, and from which...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
a6d7e889-0d62-5ffd-b33f-636187a70a07
docs
nodejs
nodejs_stream
10x
90
this[kSource].writeSomeData(chunk); callback(); } _read(size) { this[kSource].fetchSomeData(size, (data, encoding) => { this.push(Buffer.from(data, encoding)); }); } } ``` The most important aspect of a `Duplex` stream is that the `Readable` and `Writable` sides operate independently of on...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
d0928215-3d9a-582b-bb47-fa5456caf514
docs
nodejs
nodejs_stream
10x
91
const myTransform = new Transform({ writableObjectMode: true, transform(chunk, encoding, callback) { // Coerce the chunk to a number if necessary chunk |= 0; // Transform the chunk into something else. const data = chunk.toString(16); // Push the data onto the readable queue. callback(nul...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
ab1bdc48-0e76-5fec-b4c0-4095adae3503
docs
nodejs
nodejs_stream
10x
92
number of chunks, or arrive at the same time. For example, a `Hash` stream will only ever have a single chunk of output which is provided when the input is ended. A `zlib` stream will produce output that is either much smaller or much larger than its input. The `stream.Transform` class is extended to implement a [`Tra...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
f0c27c53-5358-5798-9d47-f98b7ba5ecaf
docs
nodejs
nodejs_stream
10x
93
#### new stream.Transform([options])[#](#stream_new_stream_transform_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: + `transform` [<Function>](https://dev...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
a3676bf9-7700-5403-b4f0-5e17519669f6
docs
nodejs
nodejs_stream
10x
94
function MyTransform(options) { if (!(this instanceof MyTransform)) return new MyTransform(options); Transform.call(this, options); } util.inherits(MyTransform, Transform); ``` Or, using the Simplified Constructor approach: ```None const { Transform } = require('stream'); const myTransform = new Transform({ ...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
b3bbaa2b-2609-5064-8ead-153f8efed70a
docs
nodejs
nodejs_stream
10x
95
#### transform.\_flush(callback)[#](#stream_transform_flush_callback) * `callback` [<Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) A callback function (optionally with an error argument and data) to be called when remaining data has been flushed. This function...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
36b19911-a055-59dd-b54d-aac480edae03
docs
nodejs
nodejs_stream
10x
96
but before the [`'end'`](#stream_event_end) event is emitted signaling the end of the [`Readable`](#stream_class_stream_readable) stream. Within the `transform._flush()` implementation, the `readable.push()` method may be called zero or more times, as appropriate. The `callback` function must be called when the flush ...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
63ad319b-6796-5bae-8832-b953f1ba0ea1
docs
nodejs
nodejs_stream
10x
97
the `string` passed to [`stream.write()`](#stream_writable_write_chunk_encoding_callback). If the stream's `decodeStrings` option is `false` or the stream is operating in object mode, the chunk will not be converted & will be whatever was passed to [`stream.write()`](#stream_writable_write_chunk_encoding_callba...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
951e6c2a-cc32-548f-8548-94dd1a231148
docs
nodejs
nodejs_stream
10x
98
All `Transform` stream implementations must provide a `_transform()` method to accept input and produce output. The `transform._transform()` implementation handles the bytes being written, computes an output, then passes that output off to the readable portion using the `readable.push()` method. The `transform.push()`...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
655b3392-6a00-5748-9d8d-accece31fbd5
docs
nodejs
nodejs_stream
10x
99
this.push(data); callback(); }; transform.prototype._transform = function(data, encoding, callback) { callback(null, data); }; ``` The `transform._transform()` 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. `trans...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
a8f4e636-09ff-5955-8153-4ab0cab81826
docs
nodejs
nodejs_stream
10x
100
## Additional Notes[#](#stream_additional_notes) ### Streams Compatibility with Async Generators and Async Iterators[#](#stream_streams_compatibility_with_async_generators_and_async_iterators) With the support of async generators and iterators in JavaScript, async generators are effectively a first-class language-lev...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
4e16ad2b-2157-51c2-bf86-f22205515f70
docs
nodejs
nodejs_stream
10x
101
yield 'b'; yield 'c'; } const readable = Readable.from(generate()); readable.on('data', (chunk) => { console.log(chunk); }); ``` #### Piping to Writable Streams from Async Iterators[#](#stream_piping_to_writable_streams_from_async_iterators) In the scenario of writing to a writeable stream from an async itera...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
bcbaddcf-5a97-5514-8180-3ed31aa3723b
docs
nodejs
nodejs_stream
10x
102
```None const { once } = require('events'); const writeable = fs.createWriteStream('./file'); (async function() { const readable = Readable.from(iterator); readable.pipe(writeable); // Ensure completion without errors await once(writeable, 'finish'); })(); ``` ### Compatibility with Older Node.js Versions[#]...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
e416fcdb-4bcb-5038-ad6d-b7bf4659d462
docs
nodejs
nodejs_stream
10x
103
[`'data'`](#stream_event_data) events *even when the stream was in a paused state*. In Node.js 0.10, the [`Readable`](#stream_class_stream_readable) class was added. For backward compatibility with older Node.js programs, `Readable` streams switch into "flowing mode" when a [`'data'`](#stream_event_data) event handl...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
fddab372-4e0a-5334-98e8-f98784f69655
docs
nodejs
nodejs_stream
10x
104
// WARNING! BROKEN! net.createServer((socket) => { // we add an 'end' listener, but never consume the data socket.on('end', () => { // It will never get here. socket.end('The message was received but was not processed.\n'); }); }).listen(1337); ``` Prior to Node.js 0.10, the incoming message data woul...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
44f30e3d-61c3-5097-bbbf-9b8942887022
docs
nodejs
nodejs_stream
10x
105
### `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_10x.md
70ff36f5-5b26-5a69-98c4-c60f65cb78ff
docs
nodejs
nodejs_stream
10x
106
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. ### `highWaterMark` discrepancy after calling `readable.setEncoding()`[#](#stream_highwatermark_discrepancy_after_calling_readable_setencoding) The use of `readable.setEncoding()` will ...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
09933717-ebef-56bc-9ff8-6af8fce743b1
docs
nodejs
nodejs_stream
11x
0
# Stream[src]# Source: https://nodejs.org/docs/latest-v11.x/api/stream.html Version: 11.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...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
69e85426-7056-5dbb-9816-f89c324e54ae
docs
nodejs
nodejs_stream
11x
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_11x.md
bf4dedd6-9453-5f1f-96cb-1ad2dc731507
docs
nodejs
nodejs_stream
11x
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.createDefl...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
82fcd819-c335-54de-bf5e-18f44fce27e4
docs
nodejs
nodejs_stream
11x
3
when the stream is created. Attempting to switch an existing stream into object mode is not safe. ### 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.wri...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
51926d8d-02ec-5036-a059-3704fd55557c
docs
nodejs
nodejs_stream
11x
4
queue until it is consumed. Once the total size of the internal read buffer reaches the threshold specified 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._rea...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
691daf77-6210-5599-92d1-add786f61823
docs
nodejs
nodejs_stream
11x
5
destinations of differing speeds will not overwhelm the available memory. Because [`Duplex`](#stream_class_stream_duplex) and [`Transform`](#stream_class_stream_transform) streams are both `Readable` and `Writable`, each maintains *two* separate internal buffers used for reading and writing, allowing each side to oper...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
af027a24-cc43-5397-930b-c81b1f310b9d
docs
nodejs
nodejs_stream
11x
6
## API for Stream Consumers[#](#stream_api_for_stream_consumers) Almost all Node.js applications, no matter how simple, use streams in some manner. The following is an example of using streams in a Node.js application that implements an HTTP server: ```None const http = require('http'); const server = http.createSer...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
d56182d2-3028-545f-978b-210c5613ab15
docs
nodejs
nodejs_stream
11x
7
// uh oh! bad json! res.statusCode = 400; return res.end(`error: ${er.message}`); } }); }); server.listen(1337); // $ curl localhost:1337 -d "{}" // object // $ curl localhost:1337 -d "\"foo\"" // string // $ curl localhost:1337 -d "not json" // error: Unexpected token o in JSON at position 1 ...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
e9e32826-66e2-58a5-9f04-c37ba26d3a2f
docs
nodejs
nodejs_stream
11x
8
[`Duplex`](#stream_class_stream_duplex) and [`Transform`](#stream_class_stream_transform) streams are both [`Writable`](#stream_class_stream_writable) and [`Readable`](#stream_class_stream_readable). Applications that are either writing data to or consuming data from a stream are not required to implement the stream i...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
4f2b270c-bfa9-5787-abba-39c503e4afa1
docs
nodejs
nodejs_stream
11x
9
* [TCP sockets](net.html#net_class_net_socket) * [child process stdin](child_process.html#child_process_subprocess_stdin) * [`process.stdout`](process.html#process_process_stdout), [`process.stderr`](process.html#process_process_stderr) Some of these examples are actually [`Duplex`](#stream_class_stream_duplex) stream...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
27c0e5f8-0629-5792-bac8-015dceea3a74
docs
nodejs
nodejs_stream
11x
10
#### Class: stream.Writable[#](#stream_class_stream_writable) Added in: v0.9.4 ##### Event: 'close'[#](#stream_event_close) History | Version | Changes | | --- | --- | | v10.0.0 | Add `emitClose` option to specify if `'close'` is emitted on destroy. | | v0.9.4 | Added in: v0.9.4 | The `'close'` event is emitted wh...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
b23c8f37-a4e1-529a-9bfd-7e929b87b6bb
docs
nodejs
nodejs_stream
11x
11
// Be attentive to back-pressure. function writeOneMillionTimes(writer, data, encoding, callback) { let i = 1000000; write(); function write() { let ok = true; do { i--; if (i === 0) { // last time! writer.write(data, encoding, callback); } else { // See if we sho...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
32acc17d-1227-51da-b883-d40648710e7c
docs
nodejs
nodejs_stream
11x
12
##### Event: 'finish'[#](#stream_event_finish) Added in: v0.9.4 The `'finish'` event is emitted after the [`stream.end()`](#stream_writable_end_chunk_encoding_callback) method has been called, and all data has been flushed to the underlying system. ```None const writer = getWritableStreamSomehow(); for (let i = 0; i...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
290b30b1-2179-52a1-b22c-726a51e660ed
docs
nodejs
nodejs_stream
11x
13
console.log('Something is piping into the writer.'); assert.equal(src, reader); }); reader.pipe(writer); ``` ##### Event: 'unpipe'[#](#stream_event_unpipe) Added in: v0.9.4 * `src` [<stream.Readable>](stream.html#stream_class_stream_readable) The source stream that [unpiped](#stream_readable_unpipe_destination...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
8898bfeb-5c74-5b04-a70d-52f625de770f
docs
nodejs
nodejs_stream
11x
14
reader.unpipe(writer); ``` ##### writable.cork()[#](#stream_writable_cork) Added in: v0.11.2 The `writable.cork()` method forces all written data to be buffered in memory. The buffered data will be flushed when either the [`stream.uncork()`](#stream_writable_uncork) or [`stream.end()`](#stream_writable_end_chunk_enc...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
f921e228-3673-54d4-a2f6-2423bc48bccb
docs
nodejs
nodejs_stream
11x
15
* Returns: [<this>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this) Destroy the stream. Optionally emit an `'error'` event, and emit a `'close'` event unless `emitClose` is set in `false`. After this call, the writable stream has ended and subsequent calls to `write()` or `end()` will...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
b5bb69fc-78d5-50d2-adfb-5ef3dccd119d
docs
nodejs
nodejs_stream
11x
16
| v8.0.0 | The `chunk` argument can now be a `Uint8Array` instance. | | v0.9.4 | Added in: v0.9.4 | * `chunk` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) | [<Buffer>](buffer.html#buffer_class_buffer) | [<Uint8Array>](https://developer.mozilla.org/en-US/docs/Web/JavaS...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
96406320-7cc7-5e93-8e2d-5354ddfa7eca
docs
nodejs
nodejs_stream
11x
17
* Returns: [<this>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this) 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 ...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
d5aecce4-6c9e-598a-b0a5-50caa6cd6d7c
docs
nodejs
nodejs_stream
11x
18
##### writable.setDefaultEncoding(encoding)[#](#stream_writable_setdefaultencoding_encoding) History | Version | Changes | | --- | --- | | v6.1.0 | This method now returns a reference to `writable`. | | v0.11.15 | Added in: v0.11.15 | * `encoding` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Da...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
be57a498-4352-530f-9dbb-98eb41dde1b8
docs
nodejs
nodejs_stream
11x
19
deferred using `process.nextTick()`. Doing so allows batching of all `writable.write()` calls that occur within a given Node.js event loop phase. ```None stream.cork(); stream.write('some '); stream.write('data '); process.nextTick(() => stream.uncork()); ``` If the [`writable.cork()`](#stream_writable_cork) method i...
large_dataset/raw/docs/nodejs/stream/stream_11x.md