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
3adcbe63-8a9a-533d-9eab-dde4cfa281a3
docs
nodejs
nodejs_stream
010x
35
[crypto](crypto.html) stream. 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...
large_dataset/raw/docs/nodejs/stream/stream_010x.md
35c3b1b3-6b52-5cfa-bafb-d67bfe9dbb63
docs
nodejs
nodejs_stream
010x
36
#### transform.\_transform(chunk, encoding, callback)[#](#stream_transform_transform_chunk_encoding_callback) * `chunk` Buffer | String The chunk to be transformed. Will always be a buffer unless the `decodeStrings` option was set to `false`. * `encoding` String If the chunk is a string, then this is the encoding ...
large_dataset/raw/docs/nodejs/stream/stream_010x.md
26eb0d1b-81e4-5f6b-813c-a41aab86c6e2
docs
nodejs
nodejs_stream
010x
37
Call `transform.push(outputChunk)` 0 or more times to generate output from this input chunk, depending on how much data you want to output as a result of this chunk. 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 inp...
large_dataset/raw/docs/nodejs/stream/stream_010x.md
d2e4a321-d473-5639-8046-75bea6d86d6d
docs
nodejs
nodejs_stream
010x
38
#### transform.\_flush(callback)[#](#stream_transform_flush_callback) * `callback` Function Call this function (optionally with an error argument) when you are done flushing any remaining data. Note: **This function MUST NOT be called directly.** It MAY be implemented by child classes, and if so, will be called by ...
large_dataset/raw/docs/nodejs/stream/stream_010x.md
acacc348-a191-53a1-924d-145e551b4fd0
docs
nodejs
nodejs_stream
010x
39
times, as appropriate, and call `callback` when the flush operation is complete. 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. ####...
large_dataset/raw/docs/nodejs/stream/stream_010x.md
ec9a4fc5-d7ca-5f19-8fee-a77b0338d497
docs
nodejs
nodejs_stream
010x
40
the `parseHeader` and `SimpleProtocol v1` examples above. In this example, rather than providing the input as an argument, it would be piped into the parser, which is a more idiomatic Node stream approach. ```None var util = require('util'); var Transform = require('stream').Transform; util.inherits(SimpleProtocol, T...
large_dataset/raw/docs/nodejs/stream/stream_010x.md
c196f025-e6f2-5008-8f5e-2e64875e6b9a
docs
nodejs
nodejs_stream
010x
41
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 header = Buffer.concat(this._rawHeader).toString(); try { ...
large_dataset/raw/docs/nodejs/stream/stream_010x.md
804ea520-cef9-51e0-8765-d06a8ead42b9
docs
nodejs
nodejs_stream
010x
42
### Class: stream.PassThrough[#](#stream_class_stream_passthrough) This is a trivial implementation of a [Transform](#stream_class_stream_transform) stream that simply passes the input bytes across to the output. Its purpose is mainly for examples and testing, but there are occasionally use cases where it can come in ...
large_dataset/raw/docs/nodejs/stream/stream_010x.md
fba6fce2-4735-500d-b5bb-652a20c32647
docs
nodejs
nodejs_stream
010x
43
Buffering in Writable streams happens when the user calls [`stream.write(chunk)`](#stream_writable_write_chunk_encoding_callback) repeatedly, even when `write()` returns `false`. The purpose of streams, especially with the `pipe()` method, is to limit the buffering of data to acceptable levels, so that sources and des...
large_dataset/raw/docs/nodejs/stream/stream_010x.md
6fe65856-7221-5466-8034-75eebb1542bc
docs
nodejs
nodejs_stream
010x
44
### `stream.push('')`[#](#stream_stream_push) Pushing a zero-byte string or Buffer (when not in [Object mode](#stream_object_mode)) has an interesting side effect. Because it *is* a call to [`stream.push()`](#stream_readable_push_chunk_encoding), it will end the `reading` process. However, it does *not* add any data t...
large_dataset/raw/docs/nodejs/stream/stream_010x.md
817b86da-f3b7-5627-af9f-206ed939a662
docs
nodejs
nodejs_stream
010x
45
### Compatibility with Older Node Versions[#](#stream_compatibility_with_older_node_versions) In versions of Node prior to v0.10, the Readable stream interface was simpler, but also less powerful and less useful. * Rather than waiting for you to call the `read()` method, `'data'` events would start emitting immedia...
large_dataset/raw/docs/nodejs/stream/stream_010x.md
3bdaa74d-afb0-5f19-ac40-399cc861ec46
docs
nodejs
nodejs_stream
010x
46
`'readable'` event, you no longer have to worry about losing `'data'` chunks. Most programs will continue to function normally. However, this introduces an edge case in the following conditions: * No `'data'` event handler is added. * The `pause()` and `resume()` methods are never called. For example, consider the f...
large_dataset/raw/docs/nodejs/stream/stream_010x.md
b6a1d712-d13d-526d-8e54-da0f80f817ad
docs
nodejs
nodejs_stream
010x
47
}); // 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 `wrap()` method. ### Object Mode[#](#stream_object_mode) Normally, Streams operate on Strin...
large_dataset/raw/docs/nodejs/stream/stream_010x.md
baa6777d-9327-5d03-8072-63f857f4936c
docs
nodejs
nodejs_stream
010x
48
(`EOF`). No streams in Node core are object mode streams. This pattern is only used by userland streaming libraries. You should set `objectMode` in your stream child class constructor on the options object. Setting `objectMode` mid-stream is not safe. ### State Objects[#](#stream_state_objects) [Readable](#stream_c...
large_dataset/raw/docs/nodejs/stream/stream_010x.md
b8fa3937-3826-54ef-ae6f-ebaf6a9b4bca
docs
nodejs
nodejs_stream
010x
49
util.inherits(JSONParseStream, Transform); // Gets \n-delimited JSON string data, and emits the parsed objects function JSONParseStream(options) { if (!(this instanceof JSONParseStream)) return new JSONParseStream(options); Transform.call(this, options); this._writableState.objectMode = false; this._reada...
large_dataset/raw/docs/nodejs/stream/stream_010x.md
abc81f2f-8d8d-500b-a472-3d43151608c7
docs
nodejs
nodejs_stream
010x
50
// Just handle any leftover var rem = this._buffer.trim(); if (rem) { try { var obj = JSON.parse(rem); } catch (er) { this.emit('error', er); return; } // push the parsed object out to the readable consumer this.push(obj); } cb(); }; ``` The state objects contain other u...
large_dataset/raw/docs/nodejs/stream/stream_010x.md
5e4abd68-81ff-5a0d-be51-418315363cd0
docs
nodejs
nodejs_stream
012x
0
# Stream# Source: https://nodejs.org/docs/latest-v0.12.x/api/stream.html Version: 0.12.x ```None Stability: 2 - Unstable ``` A stream is an abstract interface implemented by various objects in Node. For example a [request to an HTTP server](http.html#http_http_incomingmessage) is a stream, as is [stdout](process.htm...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
1da443a1-148e-5338-a8af-68bac2afbfef
docs
nodejs
nodejs_stream
012x
1
The second section explains the parts of the API that you need to use if you implement your own custom streams yourself. The API is designed to make this easy for you to do. The third section goes into more depth about how streams work, including some of the internal mechanisms and functions that you should probably n...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
8612f2a7-e6fe-5c24-87c2-a33c37dcd908
docs
nodejs
nodejs_stream
012x
2
somewhat different. 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) below. Almost all Node programs, no matter ...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
515af139-1845-541a-9d96-55a7a3c4ff2a
docs
nodejs
nodejs_stream
012x
3
var data = JSON.parse(body); } catch (er) { // uh oh! bad json! res.statusCode = 400; return res.end('error: ' + er.message); } // write back something interesting to the user: res.write(typeof data); res.end(); }); }); server.listen(1337); // $ curl localhost:1337 -d '...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
1308d27c-c22c-582a-92bd-664b17b8feef
docs
nodejs
nodejs_stream
012x
4
must explicitly call `stream.read()` to get chunks of data out. Streams start out in paused mode. **Note**: If no data event handlers are attached, and there are no [`pipe()`](#stream_readable_pipe_destination_options) destinations, and the stream is switched into flowing mode, then data will be lost. You can switch ...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
a61a2d97-6113-5f81-95ea-15b2b6cf92e5
docs
nodejs
nodejs_stream
012x
5
[`unpipe()`](#stream_readable_unpipe_destination) method. Note that, for backwards compatibility reasons, removing `'data'` event handlers will **not** automatically pause the stream. Also, if there are piped destinations, then calling `pause()` will not guarantee that the stream will *remain* paused once those dest...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
89754c9f-0c1d-5a05-a470-d3e324e534ed
docs
nodejs
nodejs_stream
012x
6
#### Event: 'readable'[#](#stream_event_readable) When a chunk of data can be read from the stream, it will emit a `'readable'` event. In some cases, listening for a `'readable'` event will cause some data to be read into the internal buffer from the underlying system, if it hadn't already. ```None var readable = ge...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
c8c52c1d-2eff-59dd-b877-dbe2aa6efb8e
docs
nodejs
nodejs_stream
012x
7
var rr = fs.createReadStream('foo.txt'); rr.on('readable', function() { console.log('readable:', rr.read()); }); rr.on('end', function() { console.log('end'); }); ``` The output of running this script is: ```None bash-3.2$ node test.js readable: null end ``` #### Event: 'data'[#](#stream_event_data) * `chunk` B...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
07ed27d7-7d65-58d6-a19f-dc9213eec1c4
docs
nodejs
nodejs_stream
012x
8
#### Event: 'end'[#](#stream_event_end) This event fires when there will be no more data to read. Note that the `end` event **will not fire** unless the data is completely consumed. This can be done by switching into flowing mode, or by calling `read()` repeatedly until you get to the end. ```None var readable = get...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
a7acb22a-d4ce-5004-baee-8c054a90e0b3
docs
nodejs
nodejs_stream
012x
9
#### readable.read([size])[#](#stream_readable_read_size) * `size` Number Optional argument to specify how much data to read. * Return String | Buffer | null The `read()` method pulls some data out of the internal buffer and returns it. If there is no data available, then it will return `null`. If you pass in a `siz...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
58073a3c-05a2-5b04-8c75-40ec227608d3
docs
nodejs
nodejs_stream
012x
10
If this method returns a data chunk, then it will also trigger the emission of a [`'data'` event](#stream_event_data). Note that calling `readable.read([size])` after the `end` event has been triggered will return `null`. No runtime error will be raised. #### readable.setEncoding(encoding)[#](#stream_readable_setenco...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
cfab7989-56be-558a-969d-b87f21dcf57e
docs
nodejs
nodejs_stream
012x
11
var readable = getReadableStreamSomehow(); readable.setEncoding('utf8'); readable.on('data', function(chunk) { assert.equal(typeof chunk, 'string'); console.log('got %d characters of string data', chunk.length); }); ``` #### readable.resume()[#](#stream_readable_resume) * Return: `this` This method will cause th...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
dcecb29b-bf23-5ce8-acbf-d6b538f2ebfd
docs
nodejs
nodejs_stream
012x
12
available will remain in the internal buffer. ```None var readable = getReadableStreamSomehow(); readable.on('data', function(chunk) { console.log('got %d bytes of data', chunk.length); readable.pause(); console.log('there will be no more data for 1 second'); setTimeout(function() { console.log('now data w...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
a31cafdd-8c1e-5e5b-a135-948c04e4bab5
docs
nodejs
nodejs_stream
012x
13
#### readable.pipe(destination[, options])[#](#stream_readable_pipe_destination_options) * `destination` [Writable](#stream_class_stream_writable) Stream The destination for writing data * `options` Object Pipe options + `end` Boolean End the writer when the reader ends. Default = `true` This method pulls all the d...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
71287de6-c193-52b7-afdb-a508559826e2
docs
nodejs
nodejs_stream
012x
14
process.stdin.pipe(process.stdout); ``` By default [`end()`](#stream_writable_end_chunk_encoding_callback) is called on the destination when the source stream emits `end`, so that `destination` is no longer writable. Pass `{ end: false }` as `options` to keep the destination stream open. This keeps `writer` open so t...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
180814c9-579f-5b31-b9de-1b987311405a
docs
nodejs
nodejs_stream
012x
15
var readable = getReadableStreamSomehow(); var writable = fs.createWriteStream('file.txt'); // All the data from readable goes into 'file.txt', // but only for the first second readable.pipe(writable); setTimeout(function() { console.log('stop writing to file.txt'); readable.unpipe(writable); console.log('manuall...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
988da242-b3a7-5cbf-b263-67afcf083dd9
docs
nodejs
nodejs_stream
012x
16
programs, consider implementing a [Transform](#stream_class_stream_transform) stream instead. (See API for Stream Implementors, below.) ```None // Pull off a header delimited by \n\n // use unshift() if we get too much // Call the callback with (error, header, stream) var StringDecoder = require('string_decoder').Stri...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
a73bd18a-ca72-59df-b709-7cae3dc9aa5f
docs
nodejs
nodejs_stream
012x
17
// now the body of the message can be read from the stream. callback(null, header, stream); } else { // still reading the header. header += str; } } } } ``` Note that, unlike `stream.push(chunk)`, `stream.unshift(chunk)` will not end the reading process by resetting th...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
304ae4ab-8d8c-5682-8a9f-e9717b9cdd53
docs
nodejs
nodejs_stream
012x
18
If you are using an older Node library that emits `'data'` events and has a [`pause()`](#stream_readable_pause) method that is advisory only, then you can use the `wrap()` method to create a [Readable](#stream_class_stream_readable) stream that uses the old stream as its data source. You will very rarely ever need to ...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
d2697f7c-4ea1-56fa-9ec7-9454878207af
docs
nodejs
nodejs_stream
012x
19
* [http responses, on the server](http.html#http_class_http_serverresponse) * [fs write streams](fs.html#fs_class_fs_writestream) * [zlib streams](zlib.html) * [crypto streams](crypto.html) * [tcp sockets](net.html#net_class_net_socket) * [child process stdin](child_process.html#child_process_child_stdin) * [process.st...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
6badb70b-5953-5407-9d33-29aa355bbece
docs
nodejs
nodejs_stream
012x
20
`false`. Otherwise, it will return `true`. This return value is strictly advisory. You MAY continue to write, even if it returns `false`. However, writes will be buffered in memory, so it is best not to do this excessively. Instead, wait for the `drain` event before writing more data. #### Event: 'drain'[#](#stream_e...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
382bdbb9-1db1-5a2e-b247-615983a0363b
docs
nodejs
nodejs_stream
012x
21
ok = writer.write(data, encoding); } } while (i > 0 && ok); if (i > 0) { // had to stop early! // write some more once it drains writer.once('drain', write); } } } ``` #### writable.cork()[#](#stream_writable_cork) Forces buffering of all writes. Buffered data will be fl...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
9562dd78-52bd-5950-93d4-c14c93fd6c10
docs
nodejs
nodejs_stream
012x
22
* `callback` Function Optional callback for when the stream is finished Call this method when no more data will be written to the stream. If supplied, the callback is attached as a listener on the `finish` event. ```None // write 'hello, ' and then end with 'world!' var file = fs.createWriteStream('example.txt'); fil...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
5e4f0695-411d-5c0e-b9d0-9c8630345ef3
docs
nodejs
nodejs_stream
012x
23
writer.write('hello, #' + i + '!\n'); } writer.end('this is the end\n'); writer.on('finish', function() { console.error('all writes are now complete.'); }); ``` #### Event: 'pipe'[#](#stream_event_pipe) * `src` [Readable](#stream_class_stream_readable) Stream source stream that is piping to this writable This is...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
b578fc5a-e46b-5526-abcd-9cfb3fed4750
docs
nodejs
nodejs_stream
012x
24
readable stream, removing this writable from its set of destinations. ```None var writer = getWritableStreamSomehow(); var reader = getReadableStreamSomehow(); writer.on('unpipe', function(src) { console.error('something has stopped piping into the writer'); assert.equal(src, reader); }); reader.pipe(writer); read...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
089b4c89-6006-5318-a8ee-f1c504c845ea
docs
nodejs
nodejs_stream
012x
25
### Class: stream.Transform[#](#stream_class_stream_transform) Transform streams are [Duplex](#stream_class_stream_duplex) streams where the output is in some way computed from the input. They implement both the [Readable](#stream_class_stream_readable) and [Writable](#stream_class_stream_writable) interfaces. See abo...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
a2d44dcd-f2e5-5e05-a82d-ca9aca2e8997
docs
nodejs
nodejs_stream
012x
26
of stream class you are writing: | Use-case | Class | Method(s) to implement | | --- | --- | --- | | Reading only | [Readable](#stream_class_stream_readable_1) | `_read` | | Writing only | [Writable](#stream_class_stream_writable_1) | `_write` | | Reading and writing | [Duplex](#stream_class_stream_duplex_1) | `_read`...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
d0191e34-c7f4-528b-8516-f087e4f00501
docs
nodejs
nodejs_stream
012x
27
Please see above under [API for Stream Consumers](#stream_api_for_stream_consumers) for how to consume streams in your programs. What follows is an explanation of how to implement Readable streams in your programs. #### Example: A Counting Stream[#](#stream_example_a_counting_stream) This is a basic example of a Read...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
7e05951f-a0e3-518a-9c5b-368f692b8f51
docs
nodejs
nodejs_stream
012x
28
#### Example: SimpleProtocol v1 (Sub-optimal)[#](#stream_example_simpleprotocol_v1_sub_optimal) This is similar to the `parseHeader` function described above, but implemented as a custom stream. Also, note that this implementation does not convert the incoming data to a string. However, this would be better implement...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
25af202e-87d7-5250-bf61-19ff732c65df
docs
nodejs
nodejs_stream
012x
29
this._inBody = false; this._sawFirstCr = false; // source is a readable stream, such as a socket or file this._source = source; var self = this; source.on('end', function() { self.push(null); }); // give it a kick whenever the source is readable // read(0) will not consume any bytes source.on...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
e83ca964-2f11-5394-817a-59e88bb5762a
docs
nodejs
nodejs_stream
012x
30
// still waiting for the \n\n // stash the chunk, and try again. this._rawHeader.push(chunk); this.push(''); } else { this._inBody = true; var h = chunk.slice(0, split); this._rawHeader.push(h); var header = Buffer.concat(this._rawHeader).toString(); try { ...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
2dafd860-4cc9-5f40-b2a1-de89cb61fcb1
docs
nodejs
nodejs_stream
012x
31
// from there on, just provide the data to our consumer. // careful not to push(null), since that would indicate EOF. var chunk = this._source.read(); if (chunk) this.push(chunk); } }; // Usage: // var parser = new SimpleProtocol(source); // Now parser is a readable stream that will emit 'header' // ...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
c39a1247-91a7-5868-aea6-74e230059316
docs
nodejs
nodejs_stream
012x
32
Readable constructor so that the buffering settings can be properly initialized. #### readable.\_read(size)[#](#stream_readable_read_size_1) * `size` Number Number of bytes to read asynchronously Note: **Implement this method, but do NOT call it directly.** This method is prefixed with an underscore because it is i...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
a7462d90-e97e-51b1-8119-3b71a2ddf486
docs
nodejs
nodejs_stream
012x
33
Note: once the `_read()` method is called, it will not be called again until the `push` method is called. The `size` argument is advisory. Implementations where a "read" is a single call that returns data can use this to know how much data to fetch. Implementations where that is not relevant, such as TCP or TLS, may i...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
3e228b5d-198a-5f44-a40c-94d5bf1be484
docs
nodejs
nodejs_stream
012x
34
If a value other than null is passed, The `push()` method adds a chunk of data into the queue for subsequent stream processors to consume. If `null` is passed, it signals the end of the stream (EOF), after which no more data can be written. The data added with `push` can be pulled out by calling the `read()` method wh...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
e689ee82-0474-57ba-932d-981d4902fdd7
docs
nodejs
nodejs_stream
012x
35
// Every time there's data, we push it into the internal buffer. this._source.ondata = function(chunk) { // if push() returns false, then we need to stop reading from source if (!self.push(chunk)) self._source.readStop(); }; // When the source ends, we push the EOF-signaling `null` chunk this._...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
5ec40184-e31b-5698-862d-ba85038af876
docs
nodejs
nodejs_stream
012x
36
how to implement Writable streams in your programs. #### new stream.Writable([options])[#](#stream_new_stream_writable_options) * `options` Object + `highWaterMark` Number Buffer level when [`write()`](#stream_writable_write_chunk_encoding_callback) starts returning false. Default=16kb, or 16 for `objectMode` s...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
783e8f03-aa17-5dc2-929a-0a6334a4a14c
docs
nodejs
nodejs_stream
012x
37
#### writable.\_write(chunk, encoding, callback)[#](#stream_writable_write_chunk_encoding_callback_1) * `chunk` Buffer | String The chunk to be written. Will always be a buffer unless the `decodeStrings` option was set to `false`. * `encoding` String If the chunk is a string, then this is the encoding type. Ignore...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
f82670a8-d892-5665-bb1a-8678a35ffc0c
docs
nodejs
nodejs_stream
012x
38
signal that the write completed successfully or with an error. If the `decodeStrings` flag is set in the constructor options, then `chunk` may be a string rather than a Buffer, and `encoding` will indicate the sort of string that it is. This is to support implementations that have an optimized handling for certain str...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
0c160dbe-0f8b-5595-82b6-a72228e92412
docs
nodejs
nodejs_stream
012x
39
argument) when you are done processing the supplied chunks. Note: **This function MUST NOT be called directly.** It may be implemented by child classes, and called by the internal Writable class methods only. This function is completely optional to implement. In most cases it is unnecessary. If implemented, it will...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
3a90de5f-61bf-5fdb-8d85-84614bbd646e
docs
nodejs
nodejs_stream
012x
40
Writable. It is thus up to the user to implement both the lowlevel `_read(n)` method as well as the lowlevel [`_write(chunk, encoding, callback)`](#stream_writable_write_chunk_encoding_callback_1) method on extension duplex classes. #### new stream.Duplex(options)[#](#stream_new_stream_duplex_options) * `options` Obj...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
d6b3a1ba-c5e0-5738-b2a9-fce0b2b9e960
docs
nodejs
nodejs_stream
012x
41
### Class: stream.Transform[#](#stream_class_stream_transform_1) A "transform" stream is a duplex stream where the output is causally connected in some way to the input, such as a [zlib](zlib.html) stream or a [crypto](crypto.html) stream. There is no requirement that the output be the same size as the input, the sam...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
3703282d-315f-56b2-a075-c581627de036
docs
nodejs
nodejs_stream
012x
42
#### new stream.Transform([options])[#](#stream_new_stream_transform_options) * `options` Object Passed to both Writable and Readable constructors. In classes that extend the Transform class, make sure to call the constructor so that the buffering settings can be properly initialized. #### transform.\_transform(ch...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
3bf12f70-3642-584f-87b1-d24716321d2c
docs
nodejs
nodejs_stream
012x
43
method to accept input and produce output. `_transform` should do whatever has to be done in this specific Transform class, to handle the bytes being written, and pass them off to the readable portion of the interface. Do asynchronous I/O, process things, and so on. Call `transform.push(outputChunk)` 0 or more times ...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
8670e170-0254-564c-b08a-eb0f83b6d0be
docs
nodejs
nodejs_stream
012x
44
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. #### transform.\_flush(callback)[#](#stream_transform_flush_callback) * `callback` Function Call this function (optionally with an error argument) when ...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
c9a3ba88-1cdf-5f50-bd31-8e981d9854a6
docs
nodejs
nodejs_stream
012x
45
before emitting `end` to signal the end of the readable side. Just like with `_transform`, call `transform.push(chunk)` zero or more times, as appropriate, and call `callback` when the flush operation is complete. This method is prefixed with an underscore because it is internal to the class that defines it, and shoul...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
ff25222b-578b-5c8a-b68e-31bbbeab4ba0
docs
nodejs
nodejs_stream
012x
46
#### Example: `SimpleProtocol` parser v2[#](#stream_example_simpleprotocol_parser_v2) The example above of a simple protocol parser can be implemented simply by using the higher level [Transform](#stream_class_stream_transform) stream class, similar to the `parseHeader` and `SimpleProtocol v1` examples above. In this...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
683ead5b-2ae8-5382-ac17-6e43d66075ab
docs
nodejs
nodejs_stream
012x
47
for (var i = 0; i < chunk.length; i++) { if (chunk[i] === 10) { // '\n' if (this._sawFirstCr) { split = i; break; } else { this._sawFirstCr = true; } } else { this._sawFirstCr = false; } } if (split === -1) { // still wai...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
c1fb8c0d-e936-5b95-9e6f-982f82c2778d
docs
nodejs
nodejs_stream
012x
48
// from there on, just provide the data to our consumer as-is. this.push(chunk); } done(); }; // Usage: // var parser = new SimpleProtocol(); // source.pipe(parser) // Now parser is a readable stream that will emit 'header' // with the parsed header data. ``` ### Class: stream.PassThrough[#](#stream_class...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
7ac4054d-bff8-5fd2-a039-532fe9a5419c
docs
nodejs
nodejs_stream
012x
49
`highWaterMark` option which is passed into the constructor. Buffering in Readable streams happens when the implementation calls [`stream.push(chunk)`](#stream_readable_push_chunk_encoding). If the consumer of the Stream does not call `stream.read()`, then the data will sit in the internal queue until it is consumed. ...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
210162ea-e2ea-51de-b69f-2cf25cc08ca4
docs
nodejs
nodejs_stream
012x
50
If the internal read buffer is below the `highWaterMark`, and the stream is not currently reading, then calling `read(0)` will trigger a low-level `_read` call. There is almost never a need to do this. However, you will see some cases in Node's internals where this is done, particularly in the Readable stream class in...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
119d326c-1382-5b86-abe3-a6b5db34f8e8
docs
nodejs
nodejs_stream
012x
51
So far, the only use case for this functionality is in the [tls.CryptoStream](tls.html#tls_class_cryptostream) class, which is deprecated in Node v0.12. If you find that you have to use `stream.push('')`, please consider another approach, because it almost certainly indicates that something is horribly wrong. ### Comp...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
77f1beb4-eac9-5feb-9ba5-d1f0d97a16dd
docs
nodejs
nodejs_stream
012x
52
In Node v0.10, the Readable class described below was added. For backwards compatibility with older Node programs, Readable streams switch into "flowing mode" when a `'data'` event handler is added, or when the [`resume()`](#stream_readable_resume) method is called. The effect is that, even if you are not using the new...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
43931d4b-32c1-55b4-aca2-d6bdcf97baa5
docs
nodejs
nodejs_stream
012x
53
}).listen(1337); ``` In versions of node prior to v0.10, the incoming message data would be simply discarded. However, in Node v0.10 and beyond, the socket will remain paused forever. The workaround in this situation is to call the `resume()` method to start the flow of data: ```None // Workaround net.createServer(f...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
3b20c66c-bb23-5d12-8b1f-c162ddebde34
docs
nodejs
nodejs_stream
012x
54
is. A Writable stream in object mode will always ignore the `encoding` argument to `stream.write(data, encoding)`. The special value `null` still retains its special value for object mode streams. That is, for object mode readable streams, `null` as a return value from `stream.read()` indicates that there is no more ...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
cd5d5d92-9f9f-5fe2-b0a0-cd21686b87df
docs
nodejs
nodejs_stream
012x
55
var Transform = require('stream').Transform; util.inherits(JSONParseStream, Transform); // Gets \n-delimited JSON string data, and emits the parsed objects function JSONParseStream() { if (!(this instanceof JSONParseStream)) return new JSONParseStream(); Transform.call(this, { readableObjectMode : true }); ...
large_dataset/raw/docs/nodejs/stream/stream_012x.md
ba9e0e54-1db4-5ee0-975b-9302246f803e
docs
nodejs
nodejs_stream
012x
56
var rem = this._buffer.trim(); if (rem) { try { var obj = JSON.parse(rem); } catch (er) { this.emit('error', er); return; } // push the parsed object out to the readable consumer this.push(obj); } cb(); }; ```
large_dataset/raw/docs/nodejs/stream/stream_012x.md
53cc2867-08bb-528b-8bab-48a58fc95b68
docs
nodejs
nodejs_stream
10x
0
# Stream[src]# Source: https://nodejs.org/docs/latest-v10.x/api/stream.html Version: 10.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_10x.md
560c3a3e-e476-5b7a-8317-40f50397f663
docs
nodejs
nodejs_stream
10x
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_10x.md
66e7ca8f-f9c7-5019-88be-70b0980adf81
docs
nodejs
nodejs_stream
10x
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_10x.md
969d7780-c6d9-5c97-b358-035d3b7feff6
docs
nodejs
nodejs_stream
10x
3
Stream instances are switched into object mode using the `objectMode` option 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 wi...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
03066ca9-257d-5fd2-af53-444338397add
docs
nodejs
nodejs_stream
10x
4
call [`stream.read()`](#stream_readable_read_size), the data will sit in the internal 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 buffe...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
c63b31e5-7e0d-58da-a274-c0ca721326a9
docs
nodejs
nodejs_stream
10x
5
is to limit the buffering of data to acceptable levels such that sources and 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* separ...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
4302a57c-6ec3-525f-a3dd-b07b22a2d0e2
docs
nodejs
nodejs_stream
10x
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_10x.md
8d71eb58-3f20-553d-8123-05bd5dd61d31
docs
nodejs
nodejs_stream
10x
7
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 ``` [`Writable`](#stream_...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
2578dfc2-b296-5e87-be76-2eeb10c2c494
docs
nodejs
nodejs_stream
10x
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_10x.md
2ba79f17-b864-53dc-938a-f3d69c953c87
docs
nodejs
nodejs_stream
10x
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_10x.md
e6b7bfc2-1ccd-5284-82b1-3b94f78de663
docs
nodejs
nodejs_stream
10x
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_10x.md
18357a91-4b01-5628-a4ea-366ce53aa492
docs
nodejs
nodejs_stream
10x
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_10x.md
962405cc-20f9-54d6-b83e-4b8532e7deaf
docs
nodejs
nodejs_stream
10x
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_10x.md
ac0d7060-7b27-57f8-ae32-116804d1ee76
docs
nodejs
nodejs_stream
10x
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_10x.md
7c86a9ab-5acd-5949-bba9-579e2115b436
docs
nodejs
nodejs_stream
10x
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_10x.md
7d4d9aea-3534-53ea-b2d0-c6d727af0ef9
docs
nodejs
nodejs_stream
10x
15
* Returns: [<this>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this) Destroy the stream, and emit the passed `'error'` and a `'close'` event. After this call, the writable stream has ended and subsequent calls to `write()` or `end()` will result in an `ERR_STREAM_DESTROYED` error. Impl...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
2f136896-3a67-5e39-8772-9b1e16a0bfd5
docs
nodejs
nodejs_stream
10x
16
* `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_10x.md
e86fd544-4d22-5a29-9c4b-52bc85a68180
docs
nodejs
nodejs_stream
10x
17
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 a...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
abe16c7d-5805-52d7-8d07-b50009c3d4da
docs
nodejs
nodejs_stream
10x
18
| v0.11.15 | Added in: v0.11.15 | * `encoding` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) The new default encoding * Returns: [<this>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this) The `writable.setDefaultEncoding()` method sets ...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
8aa9b82d-0c90-5fb6-9a4c-a5d214ae62ad
docs
nodejs
nodejs_stream
10x
19
process.nextTick(() => stream.uncork()); ``` If the [`writable.cork()`](#stream_writable_cork) method is called multiple times on a stream, the same 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 '); pro...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
e0144975-1e7c-5bd7-9fa8-e6bbdc30fa54
docs
nodejs
nodejs_stream
10x
20
##### writable.writableLength[#](#stream_writable_writablelength) Added in: v9.4.0 This property contains the number of bytes (or objects) in the queue ready to be written. The value provides introspection data regarding the status of the `highWaterMark`. ##### writable.write(chunk[, encoding][, callback])[#](#stre...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
301f6cdb-eee6-5a9d-ac44-6d0d0afff1f0
docs
nodejs
nodejs_stream
10x
21
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`. * `encoding` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) The encoding, if `chunk` is a string * `cal...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
24a8a438-d341-5f29-ade5-2c1faddbc55a
docs
nodejs
nodejs_stream
10x
22
first argument. To reliably detect write errors, add a listener for the `'error'` event. The return value is `true` if the internal buffer is less than the `highWaterMark` configured when the stream was created after admitting `chunk`. If `false` is returned, further attempts to write data to the stream should stop un...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
0e50ba95-9428-59ae-889e-d4a90ba6c8e6
docs
nodejs
nodejs_stream
10x
23
performance and high RSS (which is not typically released back to the system, even after the memory is no longer required). Since TCP sockets may never drain if the remote peer does not read the data, writing a socket that is not draining may lead to a remotely exploitable vulnerability. Writing data while the stream ...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
02033c87-5fd5-52dc-aa8e-31b7e756ff11
docs
nodejs
nodejs_stream
10x
24
stream.once('drain', cb); } else { process.nextTick(cb); } } // Wait for cb to be called before doing any other write. write('hello', () => { console.log('Write completed, do more writes now.'); }); ``` A `Writable` stream in object mode will always ignore the `encoding` argument. ### Readable Streams[...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
f06846e1-03ba-5df3-8e85-b95a77029ef4
docs
nodejs
nodejs_stream
10x
25
`stream.Readable` class. #### Two Reading Modes[#](#stream_two_reading_modes) `Readable` streams effectively operate in one of two modes: flowing and paused. These modes are separate from [object mode](#stream_object_mode). A [`Readable`](#stream_class_stream_readable) stream can be in object mode or not, regardless ...
large_dataset/raw/docs/nodejs/stream/stream_10x.md
7a1d91e2-fb4c-5366-a607-69c100586acc
docs
nodejs
nodejs_stream
10x
26
* Calling the [`stream.pipe()`](#stream_readable_pipe_destination_options) method to send the data to a [`Writable`](#stream_class_stream_writable). The `Readable` can switch back to paused mode using one of the following: * If there are no pipe destinations, by calling the [`stream.pause()`](#stream_readable_pause...
large_dataset/raw/docs/nodejs/stream/stream_10x.md