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
98d7395f-5a48-5a28-abca-6bfb4bb54b0d
docs
nodejs
nodejs_stream
9x
24
[`EventEmitter`](events.html#events_class_eventemitter) interface. In paused mode, the [`stream.read()`](#stream_readable_read_size) method must be called explicitly to read chunks of data from the stream. All [Readable](#stream_class_stream_readable) streams begin in paused mode but can be switched to flowing mode i...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
416b1730-82ef-5bd7-8581-8dd9212ee013
docs
nodejs
nodejs_stream
9x
25
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 backwards compatibility reasons, removing [`'data'`](#...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
993bbab5-f279-5320-be89-5247697d619d
docs
nodejs
nodejs_stream
9x
26
#### 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_9x.md
70679559-7db8-5184-a85d-88d8ff8677c4
docs
nodejs
nodejs_stream
9x
27
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.readableFlowing` to switch to `true`. ```None const { PassThrough, Writable } = require('stream'); const pass = new PassThrough(); const writabl...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
e45e8a4d-3bb2-5071-9b35-41578b4b8968
docs
nodejs
nodejs_stream
9x
28
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 the transfer and generation of data can use the [`EventEmitter`](events.html#events_class_eventemitter) and `readable.p...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
f69093d8-ab12-5546-b45c-83f483e68514
docs
nodejs
nodejs_stream
9x
29
##### 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_9x.md
0453f0e4-d035-528c-a8dd-691ad0de708b
docs
nodejs
nodejs_stream
9x
30
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_9x.md
b5df25a2-aeab-543e-8518-e481e454c668
docs
nodejs
nodejs_stream
9x
31
``` ##### 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 occur if the underlying stream is unable to generat...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
3b740a44-9040-5d97-8b5b-4e9e7c3b6ea1
docs
nodejs
nodejs_stream
9x
32
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.read()`](#stream_readable_read_size) will return the available data. In the l...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
50415e57-224d-5315-b4d9-b4fc53b0815e
docs
nodejs
nodejs_stream
9x
33
##### 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_9x.md
dea63910-c622-582c-a152-eac425254901
docs
nodejs
nodejs_stream
9x
34
```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_9x.md
b5252698-536a-51f4-ba83-4aaaa334f709
docs
nodejs
nodejs_stream
9x
35
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_9x.md
99f1562f-260e-5376-972c-5aa8342712d2
docs
nodejs
nodejs_stream
9x
36
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_9x.md
099f3023-afbb-536f-a68b-165f0aab7901
docs
nodejs
nodejs_stream
9x
37
##### readable.readableHighWaterMark[#](#stream_readable_readablehighwatermark) Added in: v9.3.0 Return the value of `highWaterMark` passed when constructing this `Readable`. ##### readable.read([size])[#](#stream_readable_read_size) Added in: v0.9.4 * `size` [<number>](https://developer.mozilla.org/en-US/docs/Web...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
c48d87d3-1a70-5ab3-8dc9-df983a79f581
docs
nodejs
nodejs_stream
9x
38
The optional `size` argument specifies a specific number of bytes to read. If `size` bytes are not available to be read, `null` will be returned *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 conta...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
46e6cf5d-af3b-5f2b-bbe9-2bbbeb279364
docs
nodejs
nodejs_stream
9x
39
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 been emitted will return `null`. No runtime error will be raised. ##### readable.readableLength[#](#stream_readab...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
155fb826-74b1-55e3-82e5-cd1b630a62d0
docs
nodejs
nodejs_stream
9x
40
stream without actually processing any of that data as illustrated in the following example: ```None getReadableStreamSomehow() .resume() .on('end', () => { console.log('Reached the end, but did not read anything.'); }); ``` ##### readable.setEncoding(encoding)[#](#stream_readable_setencoding_encoding) Add...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
aeffa974-9b9d-50a5-8215-202258275051
docs
nodejs
nodejs_stream
9x
41
output data to be interpreted as UTF-8 data, and passed as strings. Calling `readable.setEncoding('hex')` will cause the data to be encoded in hexadecimal string format. The Readable stream will properly handle multi-byte characters delivered through the stream that would otherwise become improperly decoded if simply ...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
8a76db64-18d0-5606-abaf-8939af19d1be
docs
nodejs
nodejs_stream
9x
42
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_9x.md
5cf3de5d-88d1-53f2-8224-ae9663fff710
docs
nodejs
nodejs_stream
9x
43
* `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> Chunk of data to unshift onto the read queue. Fo...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
6fef025c-2e9b-557f-a4a0-2a304b4076e9
docs
nodejs
nodejs_stream
9x
44
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 a header delimited by \n\n // use unshift() if we get ...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
a3308f4f-0c4a-5a4a-a375-8e5e749cdde6
docs
nodejs
nodejs_stream
9x
45
// 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 from the stream. callback(null, header, stream); } else { // still reading the ...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
b618f6ad-a749-5e77-8950-baf8e8ebff84
docs
nodejs
nodejs_stream
9x
46
##### 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 had streams that did not implement the entire `stream` module API as it is currently defined. (See [Compatibility](#stream_c...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
8bca5377-f2c5-561a-8930-9ecf6105527f
docs
nodejs
nodejs_stream
9x
47
const myReader = new Readable().wrap(oreader); myReader.on('readable', () => { myReader.read(); // etc. }); ``` ##### readable.destroy([error])[#](#stream_readable_destroy_error) Added in: v8.0.0 Destroy the stream, and emit `'error'`. After this call, the readable stream will release any internal resources. Impl...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
962bebcf-77da-576a-8ad2-7f915fa4566b
docs
nodejs
nodejs_stream
9x
48
* [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) streams, Transform streams implemen...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
0957171b-baac-53d6-a917-f62dd16f7d88
docs
nodejs
nodejs_stream
9x
49
## API for Stream Implementers[#](#stream_api_for_stream_implementers) The `stream` module API has been designed to make it possible to easily implement streams using JavaScript's prototypal inheritance model. First, a stream developer would declare a new JavaScript class that extends one of the four basic stream cla...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
d1485b5f-7acf-5522-8010-644a69d572b6
docs
nodejs
nodejs_stream
9x
50
| Reading and writing | [Duplex](#stream_class_stream_duplex) | `_read`, `_write`, `_writev`, `_final` | | 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 ...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
30666ecc-e545-541a-8bd2-21530469d12f
docs
nodejs
nodejs_stream
9x
51
write(chunk, encoding, callback) { // ... } }); ``` ### Implementing a Writable Stream[#](#stream_implementing_a_writable_stream) The `stream.Writable` class is extended to implement a [Writable](#stream_class_stream_writable) stream. Custom Writable streams *must* call the `new stream.Writable([options])` c...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
7bdedd77-4ed3-5237-8b3f-594827a443c9
docs
nodejs
nodejs_stream
9x
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). Defaults to `true` + `objectMode` [<boolean>](https:...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
91f04309-31e9-5529-ae3e-0e192c9093c9
docs
nodejs
nodejs_stream
9x
53
+ `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_9x.md
52a0b09f-0a08-5a81-b038-1420153b12ed
docs
nodejs
nodejs_stream
9x
54
return new MyWritable(options); Writable.call(this, options); } util.inherits(MyWritable, Writable); ``` Or, using the Simplified Constructor approach: ```None const { Writable } = require('stream'); const myWritable = new Writable({ write(chunk, encoding, callback) { // ... }, writev(chunks, callbac...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
b9c176ad-a580-5953-a60d-19ebd9cceaf6
docs
nodejs
nodejs_stream
9x
55
stream is operating in object mode, `encoding` may be ignored. * `callback` [<Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) Call this function (optionally with an error argument) when processing is complete for the supplied chunk. All Writable stream implemen...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
635ae9a1-570a-5471-a577-10c1d1c07748
docs
nodejs
nodejs_stream
9x
56
write succeeded. All calls to `writable.write()` that occur between the time `writable._write()` is called and the `callback` is called will cause the written data to be buffered. When the `callback` is invoked, the stream might emit a [`'drain'`](#stream_event_drain) event. If a stream implementation is capable of pr...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
59523c41-a047-5ed7-bfc1-a771ae583137
docs
nodejs
nodejs_stream
9x
57
internal to the class that defines it, and should never be called directly by user programs. #### 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 ...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
bbd15387-414d-5500-b3c6-cd35414956a7
docs
nodejs
nodejs_stream
9x
58
all chunks of data currently buffered in the write queue. 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. #### writable.\_destroy(err, callback)[#](#stream_writable_destroy_err_callback) Added in...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
820ea0a1-cc30-5d68-a58e-9c969426eeff
docs
nodejs
nodejs_stream
9x
59
#### writable.\_final(callback)[#](#stream_writable_final_callback) Added in: v8.0.0 * `callback` [<Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) Call this function (optionally with an error argument) when finished writing any remaining data. The `_final()` m...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
a4875546-138e-5dff-8dea-31be4e98f224
docs
nodejs
nodejs_stream
9x
60
`'error'` event to be emitted by the Writable. Throwing an Error from within `writable._write()` can result in unexpected and inconsistent behavior depending on how the stream is being used. Using the callback ensures consistent and predictable handling of errors. If a Readable stream pipes into a Writable stream when...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
d9e3fc5b-9dfa-528e-88a7-5003b3c550f6
docs
nodejs
nodejs_stream
9x
61
required elements of a custom [Writable](#stream_class_stream_writable) stream instance: ```None const { Writable } = require('stream'); class MyWritable extends Writable { constructor(options) { super(options); // ... } _write(chunk, encoding, callback) { if (chunk.toString().indexOf('a') >= 0) { ...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
67c5183e-80b9-536c-b9d7-6d5eaf6fb30c
docs
nodejs
nodejs_stream
9x
62
const state = this._writableState; this._decoder = new StringDecoder(state.defaultEncoding); this.data = ''; } _write(chunk, encoding, callback) { if (encoding === 'buffer') { chunk = this._decoder.write(chunk); } this.data += chunk; callback(); } _final(callback) { this.da...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
ceafc3ad-c095-593b-9dba-f07594d7ef26
docs
nodejs
nodejs_stream
9x
63
#### new stream.Readable([options])[#](#stream_new_stream_readable_options) * `options` [<Object>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) + `highWaterMark` [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) The maximum [nu...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
435cd8c7-fae7-57d5-a1dc-7ca09c52f726
docs
nodejs
nodejs_stream
9x
64
a single value instead of a Buffer of size n. Defaults to `false` + `read` [<Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) Implementation for the [`stream._read()`](#stream_readable_read_size_1) method. + `destroy` [<Function>](https://developer.mozill...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
e125cdb2-a628-5d22-921a-ff188bfd3208
docs
nodejs
nodejs_stream
9x
65
Or, using the Simplified Constructor approach: ```None const { Readable } = require('stream'); const myReadable = new Readable({ read(size) { // ... } }); ``` #### readable.\_read(size)[#](#stream_readable_read_size_1) * `size` [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structur...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
89633695-cd59-589d-ab37-b853a87a834c
docs
nodejs
nodejs_stream
9x
66
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_9x.md
80139d19-0fa4-5b57-90e6-1b5e36540b1e
docs
nodejs
nodejs_stream
9x
67
#### 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_9x.md
0f006eb1-fc15-5cbd-bb4f-f8cc426697fb
docs
nodejs
nodejs_stream
9x
68
* `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_9x.md
c4442cc1-403b-5701-ab1f-5809a045d8d9
docs
nodejs
nodejs_stream
9x
69
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 paused mode, the data added with `r...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
dd876a22-c05b-504b-9868-419126dc0392
docs
nodejs
nodejs_stream
9x
70
// 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_9x.md
d75f19fd-d326-55e0-98b3-36a6cfbe2c21
docs
nodejs
nodejs_stream
9x
71
`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_9x.md
49fa14ef-f25f-590c-a318-f95d22846710
docs
nodejs
nodejs_stream
9x
72
#### 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(o...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
b32bca6c-07f1-50e2-8613-64a02ba6f8ed
docs
nodejs
nodejs_stream
9x
73
`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 pr...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
7edd2fff-3a9a-5714-bbf3-ae12a22711eb
docs
nodejs
nodejs_stream
9x
74
* `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) Defaul...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
d4b3ba0e-c378-511a-8868-c5137d33d697
docs
nodejs
nodejs_stream
9x
75
+ `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_9x.md
b0204972-bfe8-55f2-b6bf-e0b861891d73
docs
nodejs
nodejs_stream
9x
76
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 d...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
d20d3a89-c802-548d-ae4a-2620690add62
docs
nodejs
nodejs_stream
9x
77
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 one anot...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
be768dbd-f176-5de2-ae1c-1669e5382338
docs
nodejs
nodejs_stream
9x
78
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_9x.md
2abd4817-5834-5158-b213-42a1aee53837
docs
nodejs
nodejs_stream
9x
79
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 [Transf...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
f76693f2-eda8-5219-9b37-9c48bb9a3c2e
docs
nodejs
nodejs_stream
9x
80
#### 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://develope...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
7f8d8e30-c541-56fd-a892-9f2e662af365
docs
nodejs
nodejs_stream
9x
81
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({ transform(chunk, encoding, cal...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
697b0e2a-82e8-5ad7-8889-e21f6728a29e
docs
nodejs
nodejs_stream
9x
82
#### 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_9x.md
87632fc7-b18f-528e-918a-9029f8dc61aa
docs
nodejs
nodejs_stream
9x
83
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 op...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
d488b21a-e722-5de1-b55d-7f35427aacbe
docs
nodejs
nodejs_stream
9x
84
* `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_9x.md
5b121007-12d1-5d99-92e0-ce70c45f1897
docs
nodejs
nodejs_stream
9x
85
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_9x.md
e4abf567-a486-5daa-a5a9-032639ebb96f
docs
nodejs
nodejs_stream
9x
86
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_9x.md
482f47cf-b237-5234-bd71-efd997a94b44
docs
nodejs
nodejs_stream
9x
87
[`'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_9x.md
b32f0404-a2ce-537f-a921-480638f4afb2
docs
nodejs
nodejs_stream
9x
88
[`'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_9x.md
a22344b1-70d2-5f49-a62b-ba6581a6dd60
docs
nodejs
nodejs_stream
9x
89
socket.on('end', () => { socket.end('The message was received but was not processed.\n'); }); // start the flow of data, discarding it. socket.resume(); }).listen(1337); ``` In addition to new Readable streams switching into flowing mode, pre-v0.10 style streams can be wrapped in a Readable class using t...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
eedb5774-c828-5898-8081-87d0ea583c10
docs
nodejs
nodejs_stream
9x
90
Readable stream class internals. ### `readable.push('')`[#](#stream_readable_push) Use of `readable.push('')` is not recommended. Pushing a zero-byte string, `Buffer` or `Uint8Array` to a stream that is not in object mode has an interesting side effect. Because it *is* a call to [`readable.push()`](#stream_readable_...
large_dataset/raw/docs/nodejs/stream/stream_9x.md
07ad1f68-c647-5567-bc63-7c5c791490a8
docs
nodejs
nodejs_stream
9x
91
This is not a problem in common cases with `latin1` or `ascii`. But it is advised to be mindful about this behavior when working with strings that could contain multi-byte characters.
large_dataset/raw/docs/nodejs/stream/stream_9x.md
6d2f5e99-5aa1-567b-bc73-6f8d4f3bb9f2
docs
nodejs
nodejs_tls
010x
0
# TLS (SSL)# Source: https://nodejs.org/docs/latest-v0.10.x/api/tls.html Version: 0.10.x ```None Stability: 3 - Stable ``` Use `require('tls')` to access this module. The `tls` module uses OpenSSL to provide Transport Layer Security and/or Secure Socket Layer: encrypted stream communication. TLS/SSL is a public/pr...
large_dataset/raw/docs/nodejs/tls/tls_010x.md
6355c98a-6e74-52ab-a8d3-fc6237804e90
docs
nodejs
nodejs_tls
010x
1
Alternatively you can send the CSR to a Certificate Authority for signing. (TODO: docs on creating a CA, for now interested users should just look at `test/fixtures/keys/Makefile` in the Node source code) To create .pfx or .p12, do this: ```None openssl pkcs12 -export -in agent5-cert.pem -inkey agent5-key.pem \ ...
large_dataset/raw/docs/nodejs/tls/tls_010x.md
343969b4-5203-5d3d-bb36-f941cffb0230
docs
nodejs
nodejs_tls
010x
2
versions of Node.js SSLv3 will not be compiled in by default. There is a way to force node into using SSLv3 only mode by explicitly specifying `secureProtocol` to `'SSLv3_method'`. The default protocol method Node.js uses is `SSLv23_method` which would be more accurately named `AutoNegotiate_method`. This method will...
large_dataset/raw/docs/nodejs/tls/tls_010x.md
c1c64b85-6f49-552a-8739-0e6f9ae7584a
docs
nodejs
nodejs_tls
010x
3
message will include `'wrong version number'`. * If your application is behaving as a secure client and communicating with a server that doesn't support methods more secure than SSLv3 then your connection won't be able to negotiate and will fail. In this case your client will emit a an `error` event. The error ...
large_dataset/raw/docs/nodejs/tls/tls_010x.md
75dc82a7-fb42-5741-b940-b2eac5646874
docs
nodejs
nodejs_tls
010x
4
* `tls.CLIENT_RENEG_WINDOW`: renegotiation window in seconds, default is 10 minutes. Don't change the defaults unless you know what you are doing. To test your server, connect to it with `openssl s_client -connect address:port` and tap `R<CR>` (that's the letter `R` followed by a carriage return) a few times. ## N...
large_dataset/raw/docs/nodejs/tls/tls_010x.md
b72fc00f-a100-5bf3-9964-ae5661643a52
docs
nodejs
nodejs_tls
010x
5
## tls.createServer(options, [secureConnectionListener])[#](#tls_tls_createserver_options_secureconnectionlistener) Creates a new [tls.Server](#tls_class_tls_server). The `connectionListener` argument is automatically set as a listener for the [secureConnection](#tls_event_secureconnection) event. The `options` object...
large_dataset/raw/docs/nodejs/tls/tls_010x.md
3c59b3ef-98b7-55cc-a3fe-b892f76922ea
docs
nodejs
nodejs_tls
010x
6
* `crl` : Either a string or list of strings of PEM encoded CRLs (Certificate Revocation List) * `ciphers`: A string describing the ciphers to use or exclude. To mitigate [BEAST attacks](http://blog.ivanristic.com/2011/10/mitigating-the-beast-attack-on-tls.html) it is recommended that you use this option in conj...
large_dataset/raw/docs/nodejs/tls/tls_010x.md
97b1450b-f78e-51fd-bd97-0f58a44d0df4
docs
nodejs
nodejs_tls
010x
7
susceptible to BEAST attacks. Do *not* use it. ``` * `handshakeTimeout`: Abort the connection if the SSL/TLS handshake does not finish in this many milliseconds. The default is 120 seconds. A `'clientError'` is emitted on the `tls.Server` object whenever a handshake times out. * `honorCipherOrder` : When choosi...
large_dataset/raw/docs/nodejs/tls/tls_010x.md
934fc3b9-03ef-57e0-bed7-a3af3ba082dc
docs
nodejs
nodejs_tls
010x
8
should be ordered by their priority). * `SNICallback`: A function that will be called if client supports SNI TLS extension. Only one argument will be passed to it: `servername`. And `SNICallback` should return SecureContext instance. (You can use `crypto.createCredentials(...).context` to get proper SecureCon...
large_dataset/raw/docs/nodejs/tls/tls_010x.md
ae8f7ac3-f9d4-5f9b-b306-9dfe294bcd3d
docs
nodejs
nodejs_tls
010x
9
protocol set the `SSL_OP_NO_SSLv3` flag. See [SSL\_CTX\_set\_options](https://www.openssl.org/docs/ssl/SSL_CTX_set_options.html) for all available options. Here is a simple example echo server: ```None var tls = require('tls'); var fs = require('fs'); var options = { key: fs.readFileSync('server-key.pem'), c...
large_dataset/raw/docs/nodejs/tls/tls_010x.md
047edef8-d484-5265-9131-c81f62a11912
docs
nodejs
nodejs_tls
010x
10
var options = { pfx: fs.readFileSync('server.pfx'), // This is necessary only if using the client certificate authentication. requestCert: true, }; var server = tls.createServer(options, function(cleartextStream) { console.log('server connected', cleartextStream.authorized ? 'authorized' : 'una...
large_dataset/raw/docs/nodejs/tls/tls_010x.md
05db36f5-a91a-548a-ba8e-805d0d3428c9
docs
nodejs
nodejs_tls
010x
11
## tls.connect(options, [callback])[#](#tls_tls_connect_options_callback) ## tls.connect(port, [host], [options], [callback])[#](#tls_tls_connect_port_host_options_callback) Creates a new client connection to the given `port` and `host` (old API) or `options.port` and `options.host`. (If `host` is omitted, it default...
large_dataset/raw/docs/nodejs/tls/tls_010x.md
de661af8-655e-57ee-ae74-f45a4d3e3ead
docs
nodejs
nodejs_tls
010x
12
* `ca`: An array of strings or `Buffer`s of trusted certificates in PEM format. If this is omitted several well known "root" CAs will be used, like VeriSign. These are used to authorize connections. * `rejectUnauthorized`: If `true`, the server certificate is verified against the list of supplied CAs. An `'error'...
large_dataset/raw/docs/nodejs/tls/tls_010x.md
44bd5d2c-6e49-52e6-8c39-217dd7aed477
docs
nodejs
nodejs_tls
010x
13
The `callback` parameter will be added as a listener for the ['secureConnect'](#tls_event_secureconnect) event. `tls.connect()` returns a [CleartextStream](#tls_class_tls_cleartextstream) object. Here is an example of a client of echo server as described previously: ```None var tls = require('tls'); var fs = require...
large_dataset/raw/docs/nodejs/tls/tls_010x.md
d899c565-24ba-5b68-87ce-63047b357abc
docs
nodejs
nodejs_tls
010x
14
server.close(); }); ``` Or ```None var tls = require('tls'); var fs = require('fs'); var options = { pfx: fs.readFileSync('client.pfx') }; var cleartextStream = tls.connect(8000, options, function() { console.log('client connected', cleartextStream.authorized ? 'authorized' : 'unauthorized'); ...
large_dataset/raw/docs/nodejs/tls/tls_010x.md
1b9ebaed-957c-579c-b8e9-a1204304f0ad
docs
nodejs
nodejs_tls
010x
15
* `credentials`: A credentials object from crypto.createCredentials( ... ) * `isServer`: A boolean indicating whether this tls connection should be opened as a server or a client. * `requestCert`: A boolean indicating whether a server should request a certificate from a connecting client. Only applies to server con...
large_dataset/raw/docs/nodejs/tls/tls_010x.md
43b0b953-e752-581c-8309-962110dc6718
docs
nodejs
nodejs_tls
010x
16
## Class: tls.Server[#](#tls_class_tls_server) This class is a subclass of `net.Server` and has the same methods on it. Instead of accepting just raw TCP connections, this accepts encrypted connections using TLS or SSL. ### Event: 'secureConnection'[#](#tls_event_secureconnection) `function (cleartextStream) {}` Th...
large_dataset/raw/docs/nodejs/tls/tls_010x.md
303a7b75-2f53-5a20-867c-220508f13c83
docs
nodejs
nodejs_tls
010x
17
`cleartextStream.servername` is a string containing servername requested with SNI. ### Event: 'clientError'[#](#tls_event_clienterror) `function (exception, securePair) { }` When a client connection emits an 'error' event before secure connection is established - it will be forwarded here. `securePair` is the `tls....
large_dataset/raw/docs/nodejs/tls/tls_010x.md
8a393113-0d0d-58b5-a2d9-304aa69545af
docs
nodejs
nodejs_tls
010x
18
### server.listen(port, [host], [callback])[#](#tls_server_listen_port_host_callback) Begin accepting connections on the specified `port` and `host`. If the `host` is omitted, the server will accept connections directed to any IPv4 address (`INADDR_ANY`). This function is asynchronous. The last parameter `callback` w...
large_dataset/raw/docs/nodejs/tls/tls_010x.md
fa3f78b7-6682-536f-87e2-810699d57394
docs
nodejs
nodejs_tls
010x
19
### server.addContext(hostname, credentials)[#](#tls_server_addcontext_hostname_credentials) Add secure context that will be used if client request's SNI hostname is matching passed `hostname` (wildcards can be used). `credentials` can contain `key`, `cert` and `ca`. ### server.maxConnections[#](#tls_server_maxconnec...
large_dataset/raw/docs/nodejs/tls/tls_010x.md
b3bb7df3-23c5-5038-ad9c-d0c6afd9f818
docs
nodejs
nodejs_tls
010x
20
## Class: tls.CleartextStream[#](#tls_class_tls_cleartextstream) This is a stream on top of the *Encrypted* stream that makes it possible to read/write an encrypted data as a cleartext data. This instance implements a duplex [Stream](stream.html#stream_stream) interfaces. It has all the common stream methods and even...
large_dataset/raw/docs/nodejs/tls/tls_010x.md
ddc49f55-8700-5b32-bd83-002b2f07d2a7
docs
nodejs
nodejs_tls
010x
21
### cleartextStream.authorized[#](#tls_cleartextstream_authorized) A boolean that is `true` if the peer certificate was signed by one of the specified CAs, otherwise `false` ### cleartextStream.authorizationError[#](#tls_cleartextstream_authorizationerror) The reason why the peer's certificate has not been verified....
large_dataset/raw/docs/nodejs/tls/tls_010x.md
317d8d83-bbb2-5fba-8b2e-732f6dfc9cdd
docs
nodejs
nodejs_tls
010x
22
valid_to: 'Nov 6 09:52:22 2029 GMT', fingerprint: '2A:7A:C2:DD:E5:F9:CC:53:72:35:99:7A:02:5A:71:38:52:EC:8A:DF' } ``` If the peer does not provide a certificate, it returns `null` or an empty object. ### cleartextStream.getCipher()[#](#tls_cleartextstream_getcipher) Returns an object representing the cipher nam...
large_dataset/raw/docs/nodejs/tls/tls_010x.md
260671ab-5e08-5cc4-ba77-2b17d086b2bc
docs
nodejs
nodejs_tls
010x
23
### cleartextStream.remoteAddress[#](#tls_cleartextstream_remoteaddress) The string representation of the remote IP address. For example, `'74.125.127.100'` or `'2001:4860:a005::68'`. ### cleartextStream.remotePort[#](#tls_cleartextstream_remoteport) The numeric representation of the remote port. For example, `443`....
large_dataset/raw/docs/nodejs/tls/tls_010x.md
019ae127-828a-523e-9335-c31cc8989367
docs
nodejs
nodejs_tls
012x
0
# TLS (SSL)# Source: https://nodejs.org/docs/latest-v0.12.x/api/tls.html Version: 0.12.x ```None Stability: 3 - Stable ``` Use `require('tls')` to access this module. The `tls` module uses OpenSSL to provide Transport Layer Security and/or Secure Socket Layer: encrypted stream communication. TLS/SSL is a public/pr...
large_dataset/raw/docs/nodejs/tls/tls_012x.md
71d3b97d-cf41-5b0e-ad27-b2c4490a40b0
docs
nodejs
nodejs_tls
012x
1
Alternatively you can send the CSR to a Certificate Authority for signing. (TODO: docs on creating a CA, for now interested users should just look at `test/fixtures/keys/Makefile` in the Node source code) To create .pfx or .p12, do this: ```None openssl pkcs12 -export -in agent5-cert.pem -inkey agent5-key.pem \ ...
large_dataset/raw/docs/nodejs/tls/tls_012x.md
dd4ab55d-2ea9-5b30-aaec-5d5b03a1a0b0
docs
nodejs
nodejs_tls
012x
2
versions of Node.js SSLv3 will not be compiled in by default. There is a way to force node into using SSLv3 only mode by explicitly specifying `secureProtocol` to `'SSLv3_method'`. The default protocol method Node.js uses is `SSLv23_method` which would be more accurately named `AutoNegotiate_method`. This method will...
large_dataset/raw/docs/nodejs/tls/tls_012x.md
426d26b0-5e12-53d4-81ba-583de3fa710f
docs
nodejs
nodejs_tls
012x
3
message will include `'wrong version number'`. * If your application is behaving as a secure client and communicating with a server that doesn't support methods more secure than SSLv3 then your connection won't be able to negotiate and will fail. In this case your client will emit a an `error` event. The error ...
large_dataset/raw/docs/nodejs/tls/tls_012x.md
1c3c0f6d-b538-5886-839f-ddd206c5166f
docs
nodejs
nodejs_tls
012x
4
* `tls.CLIENT_RENEG_WINDOW`: renegotiation window in seconds, default is 10 minutes. Don't change the defaults unless you know what you are doing. To test your server, connect to it with `openssl s_client -connect address:port` and tap `R<CR>` (that's the letter `R` followed by a carriage return) a few times. ## N...
large_dataset/raw/docs/nodejs/tls/tls_012x.md
d188fdf2-75a3-5763-a7b1-29ab2e9652ae
docs
nodejs
nodejs_tls
012x
5
decrypted by eavesdroppers if they manage to obtain the key-pair specifically generated for each session. This is achieved by randomly generating a key pair for key-agreement on every handshake (in contrary to the same key for all sessions). Methods implementing this technique, thus offering Perfect Forward Secrecy, a...
large_dataset/raw/docs/nodejs/tls/tls_012x.md
ef93ed83-d2ff-56c1-a029-a75959d49684
docs
nodejs
nodejs_tls
012x
6
## tls.getCiphers()[#](#tls_tls_getciphers) Returns an array with the names of the supported SSL ciphers. Example: ```None var ciphers = tls.getCiphers(); console.log(ciphers); // ['AES128-SHA', 'AES256-SHA', ...] ``` ## tls.createServer(options[, secureConnectionListener])[#](#tls_tls_createserver_options_secureco...
large_dataset/raw/docs/nodejs/tls/tls_012x.md
2776757f-3ccb-5bdf-b2db-0cf720dd987a
docs
nodejs
nodejs_tls
012x
7
* `cert`: A string or `Buffer` containing the certificate key of the server in PEM format. (Could be an array of certs). (Required) * `ca`: An array of strings or `Buffer`s of trusted certificates in PEM format. If this is omitted several well known "root" CAs will be used, like VeriSign. These are used to author...
large_dataset/raw/docs/nodejs/tls/tls_012x.md