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
74fe9615-f860-529f-afa9-51c05258e4f1
docs
nodejs
nodejs_stream
11x
20
##### writable.writableHighWaterMark[#](#stream_writable_writablehighwatermark) Added in: v9.3.0 * [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) Return the value of `highWaterMark` passed when constructing this `Writable`. ##### writable.writableLength[#](#stream_wr...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
a77bd1b5-0a5c-587a-80af-b79da3b7ddb3
docs
nodejs
nodejs_stream
11x
21
* `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/JavaScript/Reference/Global_Objects/Uint8Array) | [<any>](https://developer.mozilla.org/en-US/docs/Web/Jav...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
cc8da0d1-3fc3-5527-a96b-610c8e15990e
docs
nodejs
nodejs_stream
11x
22
* Returns: [<boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type) `false` if the stream wishes for the calling code to wait for the `'drain'` event to be emitted before continuing to write additional data; otherwise `true`. The `writable.write()` method writes some data t...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
7f13e3fc-09c7-56e8-a5f8-70fd8e70b21f
docs
nodejs
nodejs_stream
11x
23
delivery by the operating system), the `'drain'` event will be emitted. It is recommended that once `write()` returns false, no more chunks be written until the `'drain'` event is emitted. While calling `write()` on a stream that is not draining is allowed, Node.js will buffer all written chunks until maximum memory us...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
75753a1e-a1c3-57f9-a04f-350e03d0a8db
docs
nodejs
nodejs_stream
11x
24
If the data to be written can be generated or fetched on demand, it is recommended to encapsulate the logic into a [`Readable`](#stream_class_stream_readable) and use [`stream.pipe()`](#stream_readable_pipe_destination_options). However, if calling `write()` is preferred, it is possible to respect backpressure and avoi...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
e1b30c8d-ab29-56f5-839c-070c90229549
docs
nodejs
nodejs_stream
11x
25
* [HTTP requests, on the server](http.html#http_class_http_incomingmessage) * [fs read streams](fs.html#fs_class_fs_readstream) * [zlib streams](zlib.html) * [crypto streams](crypto.html) * [TCP sockets](net.html#net_class_net_socket) * [child process stdout and stderr](child_process.html#child_process_subprocess_stdou...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
b6811b0b-19a1-5d83-af6c-6edc7eaeb950
docs
nodejs
nodejs_stream
11x
26
[`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...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
c97eb9e1-8a22-51cd-9aa9-b3a488fee82e
docs
nodejs
nodejs_stream
11x
27
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. For backward compatibility reasons, removing [`'data'`...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
c95dda74-3dab-5ebd-a8fd-ae769c3d42b9
docs
nodejs
nodejs_stream
11x
28
Adding a [`'readable'`](#stream_event_readable) event handler automatically make the stream to stop flowing, and the data to be consumed via [`readable.read()`](#stream_readable_read_size). If the [`'readable'`](#stream_event_readable) event handler is removed, then the stream will start flowing again if there is a [`'...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
b4929f97-e294-5c52-ac19-5d1d21a5a0bd
docs
nodejs
nodejs_stream
11x
29
While in this state, attaching a listener for the `'data'` event, calling the `readable.pipe()` method, or calling the `readable.resume()` method will switch `readable.readableFlowing` to `true`, causing the `Readable` to begin actively emitting events as data is generated. Calling `readable.pause()`, `readable.unpipe...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
86f35c9c-4575-5fd1-8a48-d18a5f8e99ca
docs
nodejs
nodejs_stream
11x
30
While `readable.readableFlowing` is `false`, data may be accumulating within the stream's internal buffer. #### Choose One API Style[#](#stream_choose_one_api_style) The `Readable` stream API evolved across multiple Node.js versions and provides multiple methods of consuming stream data. In general, developers should...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
bc2d8568-44c0-57b8-b004-eeeaa455647a
docs
nodejs
nodejs_stream
11x
31
#### Class: stream.Readable[#](#stream_class_stream_readable) Added in: v0.9.4 ##### Event: 'close'[#](#stream_event_close_1) 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 ...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
d6f17e7d-603d-58b4-bc37-e12041c3076b
docs
nodejs
nodejs_stream
11x
32
operating in object mode, the chunk will be either a string or `Buffer`. For streams that are in object mode, the chunk can be any JavaScript value other than `null`. The `'data'` event is emitted whenever the stream is relinquishing ownership of a chunk of data to a consumer. This may occur whenever the stream ...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
b791a4e6-2cd4-5e7b-a51c-0cf1c62f4d12
docs
nodejs
nodejs_stream
11x
33
const readable = getReadableStreamSomehow(); readable.on('data', (chunk) => { console.log(`Received ${chunk.length} bytes of data.`); }); ``` ##### 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. The `'end'` event **will n...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
1f0fd0fd-1764-5de0-8ef7-5aee0bfa4424
docs
nodejs
nodejs_stream
11x
34
The `'error'` event may be emitted by a `Readable` implementation at any time. Typically, this may occur if the underlying stream is unable to generate data 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 `E...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
1b9bc393-6359-58e8-8930-77cb5a5fab88
docs
nodejs
nodejs_stream
11x
35
cause some amount of data to be read into an internal buffer. ```None const readable = getReadableStreamSomehow(); readable.on('readable', function() { // There is some data to read now let data; while (data = this.read()) { console.log(data); } }); ``` The `'readable'` event will also be emitted once th...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
ae6f6748-3c1f-592d-acab-19828a30ea5e
docs
nodejs
nodejs_stream
11x
36
The output of running this script is: ```None $ node test.js readable: null end ``` In general, the `readable.pipe()` and `'data'` event mechanisms are easier to understand than the `'readable'` event. However, handling `'readable'` might result in increased throughput. If both `'readable'` and [`'data'`](#stream_ev...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
2f4757f3-bd16-5b1e-be6a-98b82ee48ea3
docs
nodejs
nodejs_stream
11x
37
##### readable.destroy([error])[#](#stream_readable_destroy_error) Added in: v8.0.0 * `error` [<Error>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) Error which will be passed as payload in `'error'` event * Returns: [<this>](https://developer.mozilla.org/en-US/docs/Web/Java...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
67a6a875-3876-532d-aae2-d198ce4dafaa
docs
nodejs
nodejs_stream
11x
38
`Readable`. This is used primarily by the mechanism that underlies the `readable.pipe()` method. In most typical cases, there will be no reason to use this method directly. ```None const readable = new stream.Readable(); readable.isPaused(); // === false readable.pause(); readable.isPaused(); // === true readable.res...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
8c74e0a2-75f4-58d7-84c1-b49ea8c6ad3c
docs
nodejs
nodejs_stream
11x
39
console.log('Now data will start flowing again.'); readable.resume(); }, 1000); }); ``` The `readable.pause()` method has no effect if there is a `'readable'` event listener. ##### readable.pipe(destination[, options])[#](#stream_readable_pipe_destination_options) Added in: v0.9.4 * `destination` [<stream...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
22d26203-e788-50ee-814f-f761848ee7ea
docs
nodejs
nodejs_stream
11x
40
The `readable.pipe()` method attaches a [`Writable`](#stream_class_stream_writable) stream to the `readable`, causing it to switch automatically into flowing mode and push all of its data to the attached [`Writable`](#stream_class_stream_writable). The flow of data will be automatically managed so that the destination ...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
48ff1b64-7a60-55c8-844c-92d288343d0c
docs
nodejs
nodejs_stream
11x
41
const w = fs.createWriteStream('file.txt.gz'); r.pipe(z).pipe(w); ``` By default, [`stream.end()`](#stream_writable_end_chunk_encoding_callback) is called on the destination `Writable` stream when the source `Readable` stream emits [`'end'`](#stream_event_end), so that the destination is no longer writable. To disable...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
20843256-f95c-50c6-897d-0b73e57f6cdd
docs
nodejs
nodejs_stream
11x
42
##### readable.read([size])[#](#stream_readable_read_size) Added in: v0.9.4 * `size` [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) Optional argument to specify how much data to read. * Returns: [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_st...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
9778c42d-92e0-574e-ac11-d952b0e02edd
docs
nodejs
nodejs_stream
11x
43
`size` bytes are not available to be read, `null` will be returned *unless* the stream has ended, in which case all of the data remaining in the internal buffer will be returned. If the `size` argument is not specified, all of the data contained in the internal buffer will be returned. The `readable.read()` method sh...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
6762f4c1-f0da-5704-9a49-f85e4a9c3604
docs
nodejs
nodejs_stream
11x
44
a call to [`readable.read(size)`](#stream_readable_read_size), regardless of the value of the `size` argument. If the `readable.read()` method returns a chunk of data, a `'data'` event will also be emitted. Calling [`stream.read([size])`](#stream_readable_read_size) after the [`'end'`](#stream_event_end) event has be...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
7631f074-0429-540c-81cf-9adfdd1d4f16
docs
nodejs
nodejs_stream
11x
45
##### readable.readableLength[#](#stream_readable_readablelength) Added in: v9.4.0 * [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) This property contains the number of bytes (or objects) in the queue ready to be read. The value provides introspection data regarding t...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
eb5af734-ca2a-53cc-abda-b76c636787df
docs
nodejs
nodejs_stream
11x
46
.resume() .on('end', () => { console.log('Reached the end, but did not read anything.'); }); ``` The `readable.resume()` method has no effect if there is a `'readable'` event listener. ##### readable.setEncoding(encoding)[#](#stream_readable_setencoding_encoding) Added in: v0.9.4 * `encoding` [<string>](h...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
90f5b7f2-ea9a-5ac6-ab59-b00588cae589
docs
nodejs
nodejs_stream
11x
47
`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 simply pulled from the stream as `Buffer` objects. ```None const readable = getR...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
7d489a24-784d-559d-80c5-dbdd22ba09ce
docs
nodejs
nodejs_stream
11x
48
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 nothing. ```None const fs = require('fs'); const readable = getReadableStreamSomehow(); const writable = fs.createWriteStream('file.txt'); // All the data from re...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
a6f71bd2-cb1d-5f11-afc1-673e91d23368
docs
nodejs
nodejs_stream
11x
49
* `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) | [<any>](https://developer.mozilla.org/en-US/docs/Web/Jav...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
817e935b-edb2-57a2-9252-f28bdca192ed
docs
nodejs
nodejs_stream
11x
50
has been emitted or a runtime error will be thrown. Developers using `stream.unshift()` often should consider switching to use of a [`Transform`](#stream_class_stream_transform) stream instead. See the [API for Stream Implementers](#stream_api_for_stream_implementers) section for more information. ```None // Pull off...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
52640b3f-59b6-5440-9d3e-31b64ad56619
docs
nodejs
nodejs_stream
11x
51
const buf = Buffer.from(remaining, 'utf8'); stream.removeListener('error', callback); // Remove the 'readable' listener before unshifting stream.removeListener('readable', onReadable); if (buf.length) stream.unshift(buf); // Now the body of the message can be re...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
702946ef-3560-5e33-a9b7-7ac0e908e950
docs
nodejs
nodejs_stream
11x
52
however it is best to simply avoid calling `readable.unshift()` while in the process of performing a read. ##### readable.wrap(stream)[#](#stream_readable_wrap_stream) Added in: v0.9.4 * `stream` [<Stream>](stream.html#stream_stream) An "old style" readable stream * Returns: [<this>](https://developer.mozilla.org/en...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
6b363717-077f-5570-95f6-71f9e3a173d2
docs
nodejs
nodejs_stream
11x
53
provided as a convenience for interacting with older Node.js applications and libraries. ```None const { OldReader } = require('./old-api-module.js'); const { Readable } = require('stream'); const oreader = new OldReader(); const myReader = new Readable().wrap(oreader); myReader.on('readable', () => { myReader.read...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
1c53691d-de3a-54a3-b5d4-9d2dd20b63a3
docs
nodejs
nodejs_stream
11x
54
If the loop terminates with a `break` or a `throw`, the stream will be destroyed. In other terms, iterating over a stream will consume the stream fully. The stream will be read in chunks of size equal to the `highWaterMark` option. In the code example above, data will be in a single chunk if the file has less then 64kb...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
d3e04bf5-b2fc-5d85-865d-78e3d8a18c32
docs
nodejs
nodejs_stream
11x
55
* [zlib streams](zlib.html) * [crypto streams](crypto.html) #### Class: stream.Transform[#](#stream_class_stream_transform) Added in: v0.9.4 Transform streams are [`Duplex`](#stream_class_stream_duplex) streams where the output is in some way related to the input. Like all [`Duplex`](#stream_class_stream_duplex) str...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
eb447699-a916-5339-a4c1-eeff2aed0ee8
docs
nodejs
nodejs_stream
11x
56
[`readable._destroy()`](#stream_readable_destroy_err_callback). The default implementation of `_destroy()` for `Transform` also emit `'close'` unless `emitClose` is set in false. ### stream.finished(stream[, options], callback)[#](#stream_stream_finished_stream_options_callback) Added in: v10.0.0 * `stream` [<Stream...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
946aabc3-d94c-5d76-8dd2-1f3fa9b75cc7
docs
nodejs
nodejs_stream
11x
57
+ `writable` [<boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type) When set to `false`, the callback will be called when the stream ends even though the stream might still be writable. **Default**: `true`. * `callback` [<Function>](https://developer.mozilla.org/en-U...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
9373ab5c-ade3-59f3-b4bd-1c2abc8aafff
docs
nodejs
nodejs_stream
11x
58
The `finished` API is promisify-able as well; ```None 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...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
4a722cc5-5f10-535d-9f98-6a141b559cfe
docs
nodejs
nodejs_stream
11x
59
// Use the pipeline API to easily pipe a series of streams // together and get notified when the pipeline is fully done. // A pipeline to gzip a potentially huge tar file efficiently: pipeline( fs.createReadStream('archive.tar'), zlib.createGzip(), fs.createWriteStream('archive.tar.gz'), (err) => { if (er...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
ef9f788b-59b4-51fc-bb26-9b167e7b8c63
docs
nodejs
nodejs_stream
11x
60
First, a stream developer would declare a new JavaScript class that extends one of the four basic stream classes (`stream.Writable`, `stream.Readable`, `stream.Duplex`, or `stream.Transform`), making sure they call the appropriate parent class constructor: ```None const { Writable } = require('stream'); class MyWrita...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
355e1594-6e37-568d-8475-3035b652cde4
docs
nodejs
nodejs_stream
11x
61
| Operate on written data, then read the result | [`Transform`](#stream_class_stream_transform) | `_transform`, `_flush`, `_final` | The implementation code for a stream should *never* call the "public" methods of a stream that are intended for use by consumers (as described in the [API for Stream Consumers](#stream_a...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
4dd1bc68-8129-5ddd-bd5c-58345057f253
docs
nodejs
nodejs_stream
11x
62
### 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])` constructor and implement the `writable._write()` method. ...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
7645983e-ecbd-58be-9f2b-9d3821815ccf
docs
nodejs
nodejs_stream
11x
63
[`stream.write()`](#stream_writable_write_chunk_encoding_callback) starts returning `false`. **Default:** `16384` (16kb), or `16` for `objectMode` streams. + `decodeStrings` [<boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type) Whether to encode `string`s passed to ...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
c0e686c2-51fe-5ef1-ac53-854caed84b37
docs
nodejs
nodejs_stream
11x
64
encoding is specified as an argument to [`stream.write()`](#stream_writable_write_chunk_encoding_callback). **Default:** `'utf8'`. + `objectMode` [<boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type) Whether or not the [`stream.write(anyObj)`](#stream_writable_w...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
77b333e6-d5f7-5def-a837-b85d81f403d7
docs
nodejs
nodejs_stream
11x
65
+ `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. + `destroy` [<Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Object...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
8bbed08d-b6d0-578b-9b4a-65b600e3004a
docs
nodejs
nodejs_stream
11x
66
super(options); // ... } } ``` Or, when using pre-ES6 style constructors: ```None const { Writable } = require('stream'); const util = require('util'); function MyWritable(options) { if (!(this instanceof MyWritable)) return new MyWritable(options); Writable.call(this, options); } util.inherits(MyW...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
70b8a68f-48d7-5d10-aa53-ab4cb86a40f3
docs
nodejs
nodejs_stream
11x
67
`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_callback)....
large_dataset/raw/docs/nodejs/stream/stream_11x.md
f7b9efb0-1741-5965-9e81-a0d9de43e50b
docs
nodejs
nodejs_stream
11x
68
[`Transform`](#stream_class_stream_transform) streams provide their own implementation of the [`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 me...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
2b175763-2eee-555b-a59f-639446390752
docs
nodejs
nodejs_stream
11x
69
If the `decodeStrings` property is explicitly set to `false` in the constructor 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, ...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
d3fddbdd-8213-582f-8a74-b0fbb526e245
docs
nodejs
nodejs_stream
11x
70
* `callback` [<Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) A callback function (optionally with an error 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 i...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
e4bd75c0-469a-5b7c-b2da-88ac81a4858d
docs
nodejs
nodejs_stream
11x
71
#### writable.\_destroy(err, callback)[#](#stream_writable_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_11x.md
918d3a91-7e9e-5626-98dc-5a3d8f8164c1
docs
nodejs
nodejs_stream
11x
72
by child classes, and if so, will be called by the internal `Writable` class methods only. This optional function will be called before the stream closes, delaying the `'finish'` event until `callback` is called. This is useful to close resources or write buffered data before a stream ends. #### Errors While Writing[...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
b1e35b66-baa1-57af-9b1c-75cb833ec73f
docs
nodejs
nodejs_stream
11x
73
const myWritable = new Writable({ write(chunk, encoding, callback) { if (chunk.toString().indexOf('a') >= 0) { callback(new Error('chunk is invalid')); } else { callback(); } } }); ``` #### An Example Writable Stream[#](#stream_an_example_writable_stream) The following illustrates a rather...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
c09e6efe-2521-5fdb-bbff-bfc2aa192f80
docs
nodejs
nodejs_stream
11x
74
#### Decoding buffers in a Writable Stream[#](#stream_decoding_buffers_in_a_writable_stream) Decoding buffers is a common task, for instance, when using transformers whose input is a string. This is not a trivial process when using multi-byte characters encoding, such as UTF-8. The following example shows how to decod...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
48bfe7e1-a53c-527a-bfbe-ac1fc759db8f
docs
nodejs
nodejs_stream
11x
75
const w = new StringWritable(); w.write('currency: '); w.write(euro[0]); w.end(euro[1]); console.log(w.data); // currency: € ``` ### Implementing a Readable Stream[#](#stream_implementing_a_readable_stream) The `stream.Readable` class is extended to implement a [`Readable`](#stream_class_stream_readable) stream. C...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
89b82e8d-1d49-5f48-b13f-6ccaec5a1861
docs
nodejs
nodejs_stream
11x
76
in the internal buffer before ceasing to read from the underlying resource. **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 usin...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
b4b1f3b5-ecb7-51dd-86a8-90813d3493d5
docs
nodejs
nodejs_stream
11x
77
+ `destroy` [<Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) Implementation for the [`stream._destroy()`](#stream_readable_destroy_err_callback) method. + `autoDestroy` [<boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Bool...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
a79468a4-7cef-5fdb-89e5-c1974a65273a
docs
nodejs
nodejs_stream
11x
78
const { Readable } = require('stream'); const myReadable = new Readable({ read(size) { // ... } }); ``` #### readable.\_read(size)[#](#stream_readable_read_size_1) Added in: v0.9.4 * `size` [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) Number of bytes to rea...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
022f3ce0-312a-5eaf-b413-0521516d9c36
docs
nodejs
nodejs_stream
11x
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. The `size` argument is advisory. For implem...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
d1367b89-9561-57da-99fb-7a5eea2f326e
docs
nodejs
nodejs_stream
11x
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_11x.md
9ccf1e98-5726-545f-8630-de16b6d9a5d4
docs
nodejs
nodejs_stream
11x
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_11x.md
c8ac8b8a-da95-515f-b09c-c71aa252d7c7
docs
nodejs
nodejs_stream
11x
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_11x.md
4ea2ebd1-75e1-5582-bdd9-b05756322d10
docs
nodejs
nodejs_stream
11x
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_11x.md
06e775d2-08e3-5dd7-af60-38d6f06f2d3b
docs
nodejs
nodejs_stream
11x
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_11x.md
e2df585c-8ae5-571a-a0e5-f4952b4ee1c0
docs
nodejs
nodejs_stream
11x
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_11x.md
9b26406a-a1a1-5d1f-b9f3-5ad43a820546
docs
nodejs
nodejs_stream
11x
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_11x.md
2e99cb90-122b-5bcb-ac5a-ec339f167c2f
docs
nodejs
nodejs_stream
11x
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_11x.md
38639df5-63fa-5ed6-9fae-17520ffbe372
docs
nodejs
nodejs_stream
11x
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_11x.md
1f4bb641-3bed-5066-bce6-053b3547254d
docs
nodejs
nodejs_stream
11x
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_11x.md
d17a0c20-2852-5a21-8c73-af4d2d13541f
docs
nodejs
nodejs_stream
11x
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_11x.md
1812c99b-dc73-501b-8013-e1e85a1254df
docs
nodejs
nodejs_stream
11x
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_11x.md
18049ada-07c5-5bf2-bf95-aa37c164253f
docs
nodejs
nodejs_stream
11x
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_11x.md
dfbd69f3-9384-560d-9eab-efce31746ceb
docs
nodejs
nodejs_stream
11x
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_11x.md
0adaab6a-605a-5eea-a21e-3b6248577725
docs
nodejs
nodejs_stream
11x
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_11x.md
9f86e187-d0e8-5d0e-88a5-33e7d13cc9be
docs
nodejs
nodejs_stream
11x
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_11x.md
60e75ca3-97c3-5adc-8242-43d48025bf16
docs
nodejs
nodejs_stream
11x
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_11x.md
4b48d351-a350-5e04-a860-1f880ccb2cf6
docs
nodejs
nodejs_stream
11x
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_11x.md
de423933-c7d1-5d21-8a1f-e5873adf24d8
docs
nodejs
nodejs_stream
11x
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_11x.md
46d60d00-4f2a-5fef-b20a-e03aa80e44bb
docs
nodejs
nodejs_stream
11x
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_11x.md
6dafdca8-1d1f-5d67-8a05-8c2cb849435b
docs
nodejs
nodejs_stream
11x
100
## Additional Notes[#](#stream_additional_notes) ### Compatibility with Older Node.js Versions[#](#stream_compatibility_with_older_node_js_versions) Prior to Node.js 0.10, the `Readable` stream interface was simpler, but also less powerful and less useful. * Rather than waiting for calls to the [`stream.read()`](#st...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
caab3527-e806-504e-86bf-856cbdd913e4
docs
nodejs
nodejs_stream
11x
101
"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 [`'readable'`](#stream_event_readable) event, it is no longer n...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
303c0331-ebf2-5541-a53d-1a27765fddfc
docs
nodejs
nodejs_stream
11x
102
Prior to Node.js 0.10, the incoming message data would be simply discarded. However, in Node.js 0.10 and beyond, the socket remains paused forever. The workaround in this situation is to call the [`stream.resume()`](#stream_readable_resume) method to begin the flow of data: ```None // Workaround net.createServer((soc...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
f9602d9f-0ac9-5162-aa31-99a5642fd3b8
docs
nodejs
nodejs_stream
11x
103
If the internal read buffer is below the `highWaterMark`, and the stream is not currently reading, then calling `stream.read(0)` will trigger a low-level [`stream._read()`](#stream_readable_read_size_1) call. While most applications will almost never need to do this, there are situations within Node.js where this is d...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
0f0065ea-8160-5524-9b3a-746b04af0a7e
docs
nodejs
nodejs_stream
11x
104
### `highWaterMark` discrepancy after calling `readable.setEncoding()`[#](#stream_highwatermark_discrepancy_after_calling_readable_setencoding) The use of `readable.setEncoding()` will change the behavior of how the `highWaterMark` operates in non-object mode. Typically, the size of the current buffer is measured aga...
large_dataset/raw/docs/nodejs/stream/stream_11x.md
19c8b200-9a9f-5e16-b891-a89f2b547f9f
docs
nodejs
nodejs_stream
4x
0
# Stream# Source: https://nodejs.org/docs/latest-v4.x/api/stream.html Version: 4.x ```None Stability: 2 - Stable ``` A stream is an abstract interface implemented by various objects in Node.js. For example a [request to an HTTP server](http.html#http_class_http_incomingmessage) is a stream, as is [`process.stdout`](...
large_dataset/raw/docs/nodejs/stream/stream_4x.md
fdff5798-c4ab-5a3c-9518-56ca4e1146f4
docs
nodejs
nodejs_stream
4x
1
use if you implement your own custom streams yourself. The API is designed to make this easy for you to do. 3. The third section goes into more depth about how streams work, including some of the internal mechanisms and functions that you should probably not modify unless you definitely know what you are ...
large_dataset/raw/docs/nodejs/stream/stream_4x.md
fbb82957-d3f3-5410-95ab-19814bafe700
docs
nodejs
nodejs_stream
4x
2
It is not necessary to implement Stream interfaces in order to consume streams in your programs. If you **are** implementing streaming interfaces in your own program, please also refer to [API for Stream Implementors](#stream_api_for_stream_implementors). Almost all Node.js programs, no matter how simple, use Streams ...
large_dataset/raw/docs/nodejs/stream/stream_4x.md
a42c714e-29ae-5ab0-8efa-ce1d35625618
docs
nodejs
nodejs_stream
4x
3
// write back something interesting to the user: res.write(typeof data); res.end(); } catch (er) { // uh oh! bad json! res.statusCode = 400; return res.end(`error: ${er.message}`); } }); }); server.listen(1337); // $ curl localhost:1337 -d '{}' // object // $ curl localh...
large_dataset/raw/docs/nodejs/stream/stream_4x.md
a177dcb8-8ac7-595d-9ec2-4746ff3872d4
docs
nodejs
nodejs_stream
4x
4
A Readable stream will not start emitting data until you indicate that you are ready to receive it. Readable streams have two "modes": a **flowing mode** and a **paused mode**. When in flowing mode, data is read from the underlying system and provided to your program as fast as possible. In paused mode, you must expli...
large_dataset/raw/docs/nodejs/stream/stream_4x.md
08b4d90f-8f82-51df-874a-a2ab8f63dfb0
docs
nodejs
nodejs_stream
4x
5
* Calling the [`stream.pipe()`](#stream_readable_pipe_destination_options) method to send the data to a [Writable](#stream_class_stream_writable). You can switch back to paused mode by doing either of the following: * If there are no pipe destinations, by calling the [`stream.pause()`](#stream_readable_pause) metho...
large_dataset/raw/docs/nodejs/stream/stream_4x.md
d1e93d9a-1cd6-5b30-8785-198819472c46
docs
nodejs
nodejs_stream
4x
6
* [HTTP requests, on the server](http.html#http_class_http_incomingmessage) * [fs read streams](fs.html#fs_class_fs_readstream) * [zlib streams](zlib.html) * [crypto streams](crypto.html) * [TCP sockets](net.html#net_class_net_socket) * [child process stdout and stderr](child_process.html#child_process_child_stdout) * ...
large_dataset/raw/docs/nodejs/stream/stream_4x.md
0cabab68-97d4-50db-92a4-899808974fbc
docs
nodejs
nodejs_stream
4x
7
explicitly paused will switch the stream into flowing mode. Data will then be passed as soon as it is available. If you just want to get all the data out of the stream as fast as possible, this is the best way to do so. ```None var readable = getReadableStreamSomehow(); readable.on('data', (chunk) => { console.log(...
large_dataset/raw/docs/nodejs/stream/stream_4x.md
a01993d9-580d-5c55-8721-677ffb0f2b84
docs
nodejs
nodejs_stream
4x
8
#### Event: 'error'[#](#stream_event_error) * [<Error>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) Emitted if there was an error receiving data. #### Event: 'readable'[#](#stream_event_readable) When a chunk of data can be read from the stream, it will emit a `'readable'...
large_dataset/raw/docs/nodejs/stream/stream_4x.md
d526d8cb-865e-5a7b-83af-85cf375a168a
docs
nodejs
nodejs_stream
4x
9
In the former case, [`stream.read()`](#stream_readable_read_size) will return that 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'); var rr = fs.createReadStream('foo.txt'); rr....
large_dataset/raw/docs/nodejs/stream/stream_4x.md
99bf962b-735f-531d-8d2e-b4132586e662
docs
nodejs
nodejs_stream
4x
10
readable.isPaused() // === true readable.resume() readable.isPaused() // === false ``` #### readable.pause()[#](#stream_readable_pause) * Returns: `this` This method will cause a stream in flowing mode to stop emitting [`'data'`](#stream_event_data) events, switching out of flowing mode. Any data that becomes availa...
large_dataset/raw/docs/nodejs/stream/stream_4x.md
6559dc6d-c3e7-50fd-9a3b-3496ead21ed7
docs
nodejs
nodejs_stream
4x
11
+ `end` [<Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type) End the writer when the reader ends. Default = `true` This method pulls all the data out of a readable stream, and writes it to the supplied destination, automatically managing the flow so that the destination i...
large_dataset/raw/docs/nodejs/stream/stream_4x.md
95b06205-8559-5be2-9f98-acc49d490cde
docs
nodejs
nodejs_stream
4x
12
By default [`stream.end()`](#stream_writable_end_chunk_encoding_callback) is called on the destination when the source stream emits [`'end'`](#stream_event_end), so that `destination` is no longer writable. Pass `{ end: false }` as `options` to keep the destination stream open. This keeps `writer` open so that "Goodby...
large_dataset/raw/docs/nodejs/stream/stream_4x.md
50f385c6-f883-56d2-b6ed-9184b22955e2
docs
nodejs
nodejs_stream
4x
13
* Return [<String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) | [<Buffer>](buffer.html#buffer_class_buffer) | [<Null>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Null_type) The `read()` method pulls some data out of the internal buffer and returns...
large_dataset/raw/docs/nodejs/stream/stream_4x.md
1805eadf-ca5f-58fe-9482-626b73588406
docs
nodejs
nodejs_stream
4x
14
console.log('got %d bytes of data', chunk.length); } }); ``` If this method returns a data chunk, then it will also trigger the emission of a [`'data'`](#stream_event_data) event. Note that calling [`stream.read([size])`](#stream_readable_read_size) after the [`'end'`](#stream_event_end) event has been triggere...
large_dataset/raw/docs/nodejs/stream/stream_4x.md