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
5e8682fb-ba6b-581d-8dec-b3503e16fa9d
docs
nodejs
nodejs_stream
5x
48
Call the callback function only when the current chunk is completely consumed. Note that there may or may not be output as a result of any particular input chunk. If you supply a second argument to the callback it will be passed to the push method. In other words the following are equivalent: ```None transform.prototy...
large_dataset/raw/docs/nodejs/stream/stream_5x.md
d73f2a81-60aa-5d18-95cf-0014c475a0c0
docs
nodejs
nodejs_stream
5x
49
[Transform](#stream_class_stream_transform) stream class, similar to the `parseHeader` and `SimpleProtocol v1` examples. In this example, rather than providing the input as an argument, it would be piped into the parser, which is a more idiomatic Node.js stream approach. ```None const util = require('util'); const Tr...
large_dataset/raw/docs/nodejs/stream/stream_5x.md
5e4de981-e245-5e9c-952e-8e9084595470
docs
nodejs
nodejs_stream
5x
50
} else { this._sawFirstCr = false; } } if (split === -1) { // still waiting for the \n\n // stash the chunk, and try again. this._rawHeader.push(chunk); } else { this._inBody = true; var h = chunk.slice(0, split); this._rawHeader.push(h); var he...
large_dataset/raw/docs/nodejs/stream/stream_5x.md
f3deab79-59fa-5b2d-8541-b6c874e2d817
docs
nodejs
nodejs_stream
5x
51
// with the parsed header data. ``` ### Class: stream.Writable[#](#stream_class_stream_writable_1) `stream.Writable` is an abstract class designed to be extended with an underlying implementation of the [`stream._write(chunk, encoding, callback)`](#stream_writable_write_chunk_encoding_callback_1) method. Please see ...
large_dataset/raw/docs/nodejs/stream/stream_5x.md
74cbd0a2-1197-5399-8277-51a88de4b6f6
docs
nodejs
nodejs_stream
5x
52
+ `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). Default = `true` + `objectMode` [<Boolean>](https://...
large_dataset/raw/docs/nodejs/stream/stream_5x.md
3e37d432-d849-54b8-bfe8-016caca9a33f
docs
nodejs
nodejs_stream
5x
53
[`stream._writev()`](#stream_writable_writev_chunks_callback) method. In classes that extend the Writable class, make sure to call the constructor so that the buffering settings can be properly initialized. #### writable.\_write(chunk, encoding, callback)[#](#stream_writable_write_chunk_encoding_callback_1) * `c...
large_dataset/raw/docs/nodejs/stream/stream_5x.md
6d2a9a28-2d1c-5a03-99cc-4ad4b1415b5d
docs
nodejs
nodejs_stream
5x
54
argument) when you are done processing the supplied chunk. All Writable stream implementations must provide a [`stream._write()`](#stream_writable_write_chunk_encoding_callback_1) method to send data to the underlying resource. Note: **This function MUST NOT be called directly.** It should be implemented by child c...
large_dataset/raw/docs/nodejs/stream/stream_5x.md
9302071a-516f-5435-8e28-7132c9e983d3
docs
nodejs
nodejs_stream
5x
55
This method is prefixed with an underscore because it is internal to the class that defines it, and should not be called directly by user programs. However, you **are** expected to override this method in your own extension classes. #### writable.\_writev(chunks, callback)[#](#stream_writable_writev_chunks_callback) ...
large_dataset/raw/docs/nodejs/stream/stream_5x.md
33cdc3c3-68d9-59ed-8cc8-28ef355f5abc
docs
nodejs
nodejs_stream
5x
56
unnecessary. If implemented, it will be called with all the chunks that are buffered in the write queue. ## Simplified Constructor API[#](#stream_simplified_constructor_api) In simple cases there is now the added benefit of being able to construct a stream without inheritance. This can be done by passing the appropr...
large_dataset/raw/docs/nodejs/stream/stream_5x.md
b12c6ada-2230-53da-9fa1-7a0b6f194815
docs
nodejs
nodejs_stream
5x
57
writev: function(chunks, next) { // sets this._writev under the hood // An optional error can be passed as the first argument next() } }); ``` ### Readable[#](#stream_readable) ```None var readable = new stream.Readable({ read: function(n) { // sets this._read under the hood // push data o...
large_dataset/raw/docs/nodejs/stream/stream_5x.md
01ae61e6-91b4-55c5-941d-3df1e6187d42
docs
nodejs
nodejs_stream
5x
58
### Writable[#](#stream_writable) ```None var writable = new stream.Writable({ write: function(chunk, encoding, next) { // sets this._write under the hood // An optional error can be passed as the first argument next() } }); // or var writable = new stream.Writable({ writev: function(chunks, next)...
large_dataset/raw/docs/nodejs/stream/stream_5x.md
2d128e25-91b1-5a50-867d-101429b0d6fb
docs
nodejs
nodejs_stream
5x
59
call [`stream.read()`](#stream_readable_read_size), then the data will sit in the internal queue until it is consumed. Buffering in Writable streams happens when the user calls [`stream.write(chunk)`](#stream_writable_write_chunk_encoding_callback) repeatedly, even when it returns `false`. The purpose of streams, esp...
large_dataset/raw/docs/nodejs/stream/stream_5x.md
886cafd4-bfe1-55f4-b7be-87908a083186
docs
nodejs
nodejs_stream
5x
60
some I/O to decide how to handle data, then you had to store the chunks in some kind of buffer so that they would not be lost. * The [`stream.pause()`](#stream_readable_pause) method was advisory, rather than guaranteed. This meant that you still had to be prepared to receive [`'data'`](#stream_event_data) even...
large_dataset/raw/docs/nodejs/stream/stream_5x.md
bfc50dea-91be-51f9-9185-9c1065d4dd75
docs
nodejs
nodejs_stream
5x
61
introduces an edge case in the following conditions: * No [`'data'`](#stream_event_data) event handler is added. * The [`stream.resume()`](#stream_readable_resume) method is never called. * The stream is not piped to any writable destination. For example, consider the following code: ```None // WARNING! BROKEN! net...
large_dataset/raw/docs/nodejs/stream/stream_5x.md
ae899e8a-2366-5bb0-9222-273bcb6ea50e
docs
nodejs
nodejs_stream
5x
62
// 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 the [`stream.wrap()`](#stream_readable_wrap_stream) method. ### Object Mode[#](#stream_object_mode) No...
large_dataset/raw/docs/nodejs/stream/stream_5x.md
5c02c0a5-a076-5bb5-9776-e9fa2c3c8bff
docs
nodejs
nodejs_stream
5x
63
return value from [`stream.read()`](#stream_readable_read_size) indicates that there is no more data, and [`stream.push(null)`](#stream_readable_push_chunk_encoding) will signal the end of stream data (`EOF`). No streams in Node.js core are object mode streams. This pattern is only used by userland streaming libraries...
large_dataset/raw/docs/nodejs/stream/stream_5x.md
c884aea3-0cac-54bb-b60e-11da91e80d6e
docs
nodejs
nodejs_stream
5x
64
if (!(this instanceof JSONParseStream)) return new JSONParseStream(); Transform.call(this, { readableObjectMode : true }); this._buffer = ''; this._decoder = new StringDecoder('utf8'); } JSONParseStream.prototype._transform = function(chunk, encoding, cb) { this._buffer += this._decoder.write(chunk); ...
large_dataset/raw/docs/nodejs/stream/stream_5x.md
1b18a5f3-793e-5b0a-939e-45bcec3cdf4e
docs
nodejs
nodejs_stream
5x
65
// push the parsed object out to the readable consumer this.push(obj); } cb(); }; ``` ### `stream.read(0)`[#](#stream_stream_read_0) There are some cases where you want to trigger a refresh of the underlying readable stream mechanisms, without actually consuming any data. In that case, you can call `strea...
large_dataset/raw/docs/nodejs/stream/stream_5x.md
4c9dc071-f832-59b3-9c72-255ad27498d8
docs
nodejs
nodejs_stream
5x
66
[`stream.push()`](#stream_readable_push_chunk_encoding), it will end the `reading` process. However, it does *not* add any data to the readable buffer, so there's nothing for a user to consume. Very rarely, there are cases where you have no data to provide now, but the consumer of your stream (or, perhaps, another bit...
large_dataset/raw/docs/nodejs/stream/stream_5x.md
6e320af5-bc2c-5e5c-8de2-d39226eaaddd
docs
nodejs
nodejs_stream
6x
0
# Stream# Source: https://nodejs.org/docs/latest-v6.x/api/stream.html Version: 6.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_6x.md
f67d5748-6205-53a6-a198-25a371f08660
docs
nodejs
nodejs_stream
6x
1
types of stream instances. Developers who are primarily *consuming* stream 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 note...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
d204ae25-d907-53c7-8aac-1a00345a54e5
docs
nodejs
nodejs_stream
6x
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_6x.md
f5c520b8-d0de-50e3-b8b6-9eea471c4702
docs
nodejs
nodejs_stream
6x
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_6x.md
69475066-3721-505c-925d-dbc1d9a8b48c
docs
nodejs
nodejs_stream
6x
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_6x.md
3566095d-5a72-5a2b-9281-5a6d25074bc3
docs
nodejs
nodejs_stream
6x
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_6x.md
6ccc2ec0-d8d5-5d85-bdad-3ac2abd2698d
docs
nodejs
nodejs_stream
6x
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_6x.md
a371e43d-6805-59d1-bb43-8402d6ba9405
docs
nodejs
nodejs_stream
6x
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_6x.md
b4dbf416-c7ad-5db0-8837-c178d5e50bd9
docs
nodejs
nodejs_stream
6x
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_6x.md
d0d2c78d-b7a8-5191-9eb0-ff36d1fb4275
docs
nodejs
nodejs_stream
6x
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_6x.md
a199459e-4d3a-524c-b1ac-9d33d6b3f05f
docs
nodejs
nodejs_stream
6x
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_6x.md
0cbfd8ea-24a4-502c-8c60-935ed8e8b196
docs
nodejs
nodejs_stream
6x
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_6x.md
5bd670bf-6f02-5db0-bd88-7ceeca425485
docs
nodejs
nodejs_stream
6x
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_6x.md
6e4dcad7-539f-54c9-8540-e8dae890e7f9
docs
nodejs
nodejs_stream
6x
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_6x.md
ca840b20-44d7-554f-849e-298560fa30e2
docs
nodejs
nodejs_stream
6x
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_6x.md
028281d8-b64e-57e8-8543-301ea6861cdb
docs
nodejs
nodejs_stream
6x
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_6x.md
2585bdb8-f8ce-555a-9891-c5962b13d0aa
docs
nodejs
nodejs_stream
6x
16
* Returns: [<this>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this) The `writable.setDefaultEncoding()` method sets the default `encoding` for a [Writable](#stream_class_stream_writable) stream. ##### writable.uncork()[#](#stream_writable_uncork) Added in: v0.11.2 The `writable.unc...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
1d0c3337-2e07-5a8f-94c1-9f4c0d965080
docs
nodejs
nodejs_stream
6x
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_6x.md
52b6d32a-090f-59c3-a830-ed6552212a90
docs
nodejs
nodejs_stream
6x
18
* 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_6x.md
e7125349-6414-5c93-8452-bc1f3f4b84ad
docs
nodejs
nodejs_stream
6x
19
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 usag...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
b1bb0367-e41a-5372-9726-727cdf82e92c
docs
nodejs
nodejs_stream
6x
20
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 avoid ...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
2195b7f3-585c-55ec-bd78-1020d9c687cd
docs
nodejs
nodejs_stream
6x
21
* [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_6x.md
d43694d5-2312-571f-98f8-aef1a59ec8a3
docs
nodejs
nodejs_stream
6x
22
All [Readable](#stream_class_stream_readable) streams begin in paused mode but can be switched to flowing mode in one of the following ways: * Adding a [`'data'`](#stream_event_data) event handler. * Calling the [`stream.resume()`](#stream_readable_resume) method. * Calling the [`stream.pipe()`](#stream_readable_pipe_...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
7d744120-2b3d-5b66-9df2-2ae86a571a96
docs
nodejs
nodejs_stream
6x
23
the consuming mechanism is disabled or taken away, the Readable will *attempt* to stop generating the data. *Note*: For backwards compatibility reasons, removing [`'data'`](#stream_event_data) event handlers will **not** automatically pause the stream. Also, if there are piped destinations, then calling [`stream.pause...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
a204691a-085d-5dda-bfee-2020b9e1f545
docs
nodejs
nodejs_stream
6x
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_6x.md
07eefd04-7c69-54b2-85ea-705c5e9d2b28
docs
nodejs
nodejs_stream
6x
25
will cause the `readable._readableState.flowing` to be set as `false`, temporarily halting the flowing of events but *not* halting the generation of data. While in this state, attaching a listener for the `'data'` event would not cause `readable._readableState.flowing` to switch to `true`. ```None const { PassThrough,...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
e39977f6-eb0d-5c19-abbf-f52eafa99e55
docs
nodejs
nodejs_stream
6x
26
*one* of the methods of consuming data and *should never* use multiple methods to consume data from a single stream. 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. Developers that require more fine-grained control over t...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
ee5e2d01-2366-5eb6-b902-bc1e8ade65e2
docs
nodejs
nodejs_stream
6x
27
##### Event: 'data'[#](#stream_event_data) Added in: v0.9.4 * `chunk` [<Buffer>](buffer.html#buffer_class_buffer) | [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) | <any> The chunk of data. For streams that are not operating in object mode, the chunk will be either a...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
bc4d95bb-fc1a-57af-94f8-ac3c92407aaf
docs
nodejs
nodejs_stream
6x
28
soon as it is available. The listener callback will be passed the chunk of data as a string if a default encoding has been specified for the stream using the `readable.setEncoding()` method; otherwise the data will be passed as a `Buffer`. ```None const readable = getReadableStreamSomehow(); readable.on('data', (chun...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
580c2778-5d64-51c3-a8db-85cc46301321
docs
nodejs
nodejs_stream
6x
29
console.log('There will be no more data.'); }); ``` ##### Event: 'error'[#](#stream_event_error_1) Added in: v0.9.4 * [<Error>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) The `'error'` event may be emitted by a Readable implementation at any time. Typically, this may o...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
84a8fbaf-8cd7-5925-8ba5-bd61ac553743
docs
nodejs
nodejs_stream
6x
30
The `'readable'` event will also be emitted once the end of the stream data has been reached but before the `'end'` event is emitted. Effectively, the `'readable'` event indicates that the stream has new information: either new data is available or the end of the stream has been reached. In the former case, [`stream.r...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
f5b761e9-c3ad-5310-9895-48f33bba4f0c
docs
nodejs
nodejs_stream
6x
31
##### 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 un...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
7b6daf5f-877d-5a74-b493-6cff3fe72239
docs
nodejs
nodejs_stream
6x
32
```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_6x.md
af849853-00ae-58fe-9a8d-b911db46eb0e
docs
nodejs
nodejs_stream
6x
33
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 Writable stream is not overwhelmed by a faster Readable stream. The following example pipes all of the data fro...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
ac312496-9b29-548f-a4a8-59b3253df960
docs
nodejs
nodejs_stream
6x
34
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 this default behavior, the `end` option can be passed as `false`, causing ...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
72d5ce10-f790-5ea9-8d83-322695f55b77
docs
nodejs
nodejs_stream
6x
35
##### 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_6x.md
cb6edf12-ce72-58d0-99e5-58567ec5b852
docs
nodejs
nodejs_stream
6x
36
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 should only be called on Readable streams operating in paused mode. In flowing...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
5d3ecbf6-4b5c-5bf9-be11-3efc578daabe
docs
nodejs
nodejs_stream
6x
37
*Note:* If the `readable.read()` method returns a chunk of data, a `'data'` event will also be emitted. *Note*: Calling [`stream.read([size])`](#stream_readable_read_size) after the [`'end'`](#stream_event_end) event has been emitted will return `null`. No runtime error will be raised. ##### readable.resume()[#](#str...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
b2ae1a5b-b126-5ad8-903b-cef2c90f6ef6
docs
nodejs
nodejs_stream
6x
38
##### 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_6x.md
d9ccdfb4-8642-59b1-9bd0-4927657f378f
docs
nodejs
nodejs_stream
6x
39
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 data', c...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
1f81a86d-6e7b-5d15-bd3b-8d0b159b6f82
docs
nodejs
nodejs_stream
6x
40
// 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('Manually close the file stream'); writable.end(); }, 1000); ``` ##### readable.unshift(chunk)[#](#str...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
445dc3b6-a7a2-5d13-83b1-1ac1d8f9e5a2
docs
nodejs
nodejs_stream
6x
41
[`'end'`](#stream_event_end) event 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 ...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
bd69338c-254e-5fa3-8634-b6ed3b528ef1
docs
nodejs
nodejs_stream
6x
42
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 read...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
57bc4b3b-a474-52d1-9dcb-56a6029c8b2b
docs
nodejs
nodejs_stream
6x
43
appropriately, 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 Versions of Node.js prior to v0.10 h...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
719511ef-ad21-5a9c-83cb-d1d321a33510
docs
nodejs
nodejs_stream
6x
44
const OldReader = require('./old-api-module.js').OldReader; const Readable = require('stream').Readable; const oreader = new OldReader(); const myReader = new Readable().wrap(oreader); myReader.on('readable', () => { myReader.read(); // etc. }); ``` ### Duplex and Transform Streams[#](#stream_duplex_and_transform_s...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
6f7f68eb-0346-5da2-b1f1-57415e18de51
docs
nodejs
nodejs_stream
6x
45
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.html) ## API for Stream Implementers[#](#stream_api_for_stream_implementers) The `stream` module API has...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
c3bc0904-1df4-501e-8ce6-edb8ff1a617a
docs
nodejs
nodejs_stream
6x
46
| Use-case | Class | Method(s) to implement | | --- | --- | --- | | Reading only | [Readable](#stream_class_stream_readable) | `_read` | | Writing only | [Writable](#stream_class_stream_writable) | `_write`, `_writev` | | Reading and writing | [Duplex](#stream_class_stream_duplex) | `_read`, `_write`, `_writev` | | Ope...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
8182c52e-52d2-5a12-ad36-291a2433b70f
docs
nodejs
nodejs_stream
6x
47
`stream.Writable`, `stream.Readable`, `stream.Duplex` or `stream.Transform` objects and passing appropriate methods as constructor options. For example: ```None const Writable = require('stream').Writable; const myWritable = new Writable({ write(chunk, encoding, callback) { // ... } }); ``` ### Implementing...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
b68b80bb-3d48-5dc0-971d-4c93ccc933ba
docs
nodejs
nodejs_stream
6x
48
+ `highWaterMark` [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) Buffer level when [`stream.write()`](#stream_writable_write_chunk_encoding_callback) starts returning `false`. Defaults to `16384` (16kb), or `16` for `objectMode` streams. + `decodeStrings` [<b...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
6ebaaf83-3682-5a14-b12a-37428de71db0
docs
nodejs
nodejs_stream
6x
49
+ `write` [<Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) Implementation for the [`stream._write()`](#stream_writable_write_chunk_encoding_callback_1) method. + `writev` [<Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
c1006845-d32b-5b4f-b26a-556013e44ba8
docs
nodejs
nodejs_stream
6x
50
const Writable = require('stream').Writable; const myWritable = new Writable({ write(chunk, encoding, callback) { // ... }, writev(chunks, callback) { // ... } }); ``` #### writable.\_write(chunk, encoding, callback)[#](#stream_writable_write_chunk_encoding_callback_1) * `chunk` [<Buffer>](buffer.htm...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
95e996b2-9aae-5afe-93c2-e292ebe198ef
docs
nodejs
nodejs_stream
6x
51
argument) when processing is complete for the supplied chunk. All Writable stream implementations must provide a [`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 imple...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
899c8efe-9ec7-5368-bb80-7551c675bfe5
docs
nodejs
nodejs_stream
6x
52
the written data to be buffered. Once the `callback` is invoked, the stream will 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 const...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
5c62c331-acbb-537a-8c7d-ec713b503f87
docs
nodejs
nodejs_stream
6x
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_6x.md
3cf6ddd9-ef3f-59f8-8315-e007124e12bb
docs
nodejs
nodejs_stream
6x
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_6x.md
596b619f-6855-595d-83e3-80f94fddb6ff
docs
nodejs
nodejs_stream
6x
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_6x.md
8d936dcc-709d-586a-b4d6-6a4f5a58815e
docs
nodejs
nodejs_stream
6x
56
characters encoding, such as UTF-8. The following example shows how to decode 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 { construct...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
ef9e6907-c33f-5685-bf9b-0a628cc7d804
docs
nodejs
nodejs_stream
6x
57
### 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_6x.md
2adec2b2-6192-5c66-8b9e-a5abe6d5ed71
docs
nodejs
nodejs_stream
6x
58
+ `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. Defaults to `null` + `objectMode` [<boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#B...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
880f84ae-bb16-5ced-b474-4add10c0102e
docs
nodejs
nodejs_stream
6x
59
const Readable = require('stream').Readable; const util = require('util'); function MyReadable(options) { if (!(this instanceof MyReadable)) return new MyReadable(options); Readable.call(this, options); } util.inherits(MyReadable, Readable); ``` Or, using the Simplified Constructor approach: ```None const Re...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
19c599d9-38ac-59e4-b67c-8f02244b02af
docs
nodejs
nodejs_stream
6x
60
When `readable._read()` is called, if data is available from the resource, the implementation should begin pushing that data into the read queue using the [`this.push(dataChunk)`](#stream_readable_push_chunk_encoding) method. `_read()` should continue reading from the resource and pushing data until `readable.push()` r...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
22a81a29-99ac-513a-9e3c-25cd84baa687
docs
nodejs
nodejs_stream
6x
61
`size` bytes are available before calling [`stream.push(chunk)`](#stream_readable_push_chunk_encoding). The `readable._read()` 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. #### readable.push(chunk[, encoding])[#](#stre...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
9b726e00-c702-5dc9-9415-24c520bbe07a
docs
nodejs
nodejs_stream
6x
62
pushed; `false` otherwise. When `chunk` is a `Buffer` 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 paused mode, the da...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
2da507e8-3ddf-531c-9255-45cbda11385b
docs
nodejs
nodejs_stream
6x
63
// 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_6x.md
9553e711-90b7-5534-b1e1-319f858683ad
docs
nodejs
nodejs_stream
6x
64
#### Errors While Reading[#](#stream_errors_while_reading) It is recommended that errors occurring during the processing of the `readable._read()` method are emitted using the `'error'` event rather than being thrown. Throwing an Error from within `readable._read()` can result in unexpected and inconsistent behavior d...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
273a41c4-27cf-506f-b6dc-6526e89720df
docs
nodejs
nodejs_stream
6x
65
constructor(opt) { super(opt); this._max = 1000000; this._index = 1; } _read() { const i = this._index++; if (i > this._max) this.push(null); else { const str = '' + i; const buf = Buffer.from(str, 'ascii'); this.push(buf); } } } ``` ### Implementing a Duple...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
3f254671-5303-5946-a2cf-2423605ea339
docs
nodejs
nodejs_stream
6x
66
for both base classes due to overriding [`Symbol.hasInstance`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance) on `stream.Writable`. Custom Duplex streams *must* call the `new stream.Duplex([options])` constructor and implement *both* the `readable._read()` and `wri...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
fedb52ab-3c4b-55c1-8fd4-ffbd5253e304
docs
nodejs
nodejs_stream
6x
67
+ `readableObjectMode` [<boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type) Defaults to `false`. Sets `objectMode` for readable side of the stream. Has no effect if `objectMode` is `true`. + `writableObjectMode` [<boolean>](https://developer.mozilla.org/en-US/doc...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
cbe66d15-f53d-5a95-8531-34b529eddfe8
docs
nodejs
nodejs_stream
6x
68
const Duplex = require('stream').Duplex; const myDuplex = new Duplex({ 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 ...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
623d9b52-b305-58f4-bd90-60708ec63718
docs
nodejs
nodejs_stream
6x
69
if (Buffer.isBuffer(chunk)) chunk = chunk.toString(); 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 t...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
1205b99d-d462-5fde-aafe-9c58609ab968
docs
nodejs
nodejs_stream
6x
70
// All Transform streams are also Duplex Streams 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 t...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
6dcaa936-d155-51d5-a841-03f73fc4115b
docs
nodejs
nodejs_stream
6x
71
*Note*: There is no requirement that the output be the same size as the input, the same 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...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
32af8766-d08e-5e98-8188-dbce6f7a7d55
docs
nodejs
nodejs_stream
6x
72
the output on the Readable side is not consumed. #### 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 fie...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
11185898-efd7-5649-82e4-47bd0aa66455
docs
nodejs
nodejs_stream
6x
73
const Transform = require('stream').Transform; const util = require('util'); 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 ...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
02a295b0-9ca5-5059-b3fd-ff62a28e1e7b
docs
nodejs
nodejs_stream
6x
74
[`transform._flush()`](#stream_transform_flush_callback) has been called. #### 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)...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
3fce3bfb-fa19-5a69-af11-9597fbf9391c
docs
nodejs
nodejs_stream
6x
75
method. This will be called when there is no more written data to be consumed, 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 ...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
45144d25-0563-52c4-8261-d0cdc66f0d42
docs
nodejs
nodejs_stream
6x
76
* `encoding` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) If the chunk is a string, then this is the encoding type. If chunk is a buffer, then this is the special value - 'buffer', ignore it in this case. * `callback` [<Function>](https://developer.mozilla.org/en-U...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
7a25ac82-3a90-555a-9366-d0b671e0ea9c
docs
nodejs
nodejs_stream
6x
77
The `transform.push()` method may be called zero or more times to generate output from a single input chunk, depending on how much is to be output as a result of the chunk. It is possible that no output is generated from any given chunk of input data. The `callback` function must be called only when the current chunk...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
c5868fc9-ee97-5d38-8e95-8f5de667a147
docs
nodejs
nodejs_stream
6x
78
user programs. `transform._transform()` is never called in parallel; streams implement a queue mechanism, and to receive the next chunk, `callback` must be called, either synchronously or asynchronously. #### Class: stream.PassThrough[#](#stream_class_stream_passthrough) The `stream.PassThrough` class is a trivial i...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
960d83bf-91e3-5fbf-b945-09f8683f7530
docs
nodejs
nodejs_stream
6x
79
[`'data'`](#stream_event_data) events would begin emitting immediately. Applications that would need to perform some amount of work to decide how to handle data were required to store read data into buffers so the data would not be lost. * The [`stream.pause()`](#stream_readable_pause) method was advisory, rather...
large_dataset/raw/docs/nodejs/stream/stream_6x.md
c132c51f-604a-5ac9-9574-58feb1caa441
docs
nodejs
nodejs_stream
6x
80
[`'data'`](#stream_event_data) chunks. While most applications will continue to function normally, this introduces an edge case in the following conditions: * No [`'data'`](#stream_event_data) event listener is added. * The [`stream.resume()`](#stream_readable_resume) method is never called. * The stream is not piped...
large_dataset/raw/docs/nodejs/stream/stream_6x.md