@types/node 20.1.2 → 20.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
node/ts4.8/events.d.ts CHANGED
@@ -310,21 +310,63 @@ declare module 'events' {
310
310
  */
311
311
  static setMaxListeners(n?: number, ...eventTargets: Array<_DOMEventTarget | NodeJS.EventEmitter>): void;
312
312
  /**
313
- * This symbol shall be used to install a listener for only monitoring `'error'`
314
- * events. Listeners installed using this symbol are called before the regular
315
- * `'error'` listeners are called.
313
+ * This symbol shall be used to install a listener for only monitoring `'error'`events. Listeners installed using this symbol are called before the regular`'error'` listeners are called.
316
314
  *
317
- * Installing a listener using this symbol does not change the behavior once an
318
- * `'error'` event is emitted, therefore the process will still crash if no
315
+ * Installing a listener using this symbol does not change the behavior once an`'error'` event is emitted. Therefore, the process will still crash if no
319
316
  * regular `'error'` listener is installed.
317
+ * @since v13.6.0, v12.17.0
320
318
  */
321
319
  static readonly errorMonitor: unique symbol;
320
+ /**
321
+ * Value: `Symbol.for('nodejs.rejection')`
322
+ *
323
+ * See how to write a custom `rejection handler`.
324
+ * @since v13.4.0, v12.16.0
325
+ */
322
326
  static readonly captureRejectionSymbol: unique symbol;
323
327
  /**
324
- * Sets or gets the default captureRejection value for all emitters.
328
+ * Value: [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
329
+ *
330
+ * Change the default `captureRejections` option on all new `EventEmitter` objects.
331
+ * @since v13.4.0, v12.16.0
325
332
  */
326
- // TODO: These should be described using static getter/setter pairs:
327
333
  static captureRejections: boolean;
334
+ /**
335
+ * By default, a maximum of `10` listeners can be registered for any single
336
+ * event. This limit can be changed for individual `EventEmitter` instances
337
+ * using the `emitter.setMaxListeners(n)` method. To change the default
338
+ * for _all_`EventEmitter` instances, the `events.defaultMaxListeners`property can be used. If this value is not a positive number, a `RangeError`is thrown.
339
+ *
340
+ * Take caution when setting the `events.defaultMaxListeners` because the
341
+ * change affects _all_`EventEmitter` instances, including those created before
342
+ * the change is made. However, calling `emitter.setMaxListeners(n)` still has
343
+ * precedence over `events.defaultMaxListeners`.
344
+ *
345
+ * This is not a hard limit. The `EventEmitter` instance will allow
346
+ * more listeners to be added but will output a trace warning to stderr indicating
347
+ * that a "possible EventEmitter memory leak" has been detected. For any single`EventEmitter`, the `emitter.getMaxListeners()` and `emitter.setMaxListeners()`methods can be used to
348
+ * temporarily avoid this warning:
349
+ *
350
+ * ```js
351
+ * import { EventEmitter } from 'node:events';
352
+ * const emitter = new EventEmitter();
353
+ * emitter.setMaxListeners(emitter.getMaxListeners() + 1);
354
+ * emitter.once('event', () => {
355
+ * // do stuff
356
+ * emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0));
357
+ * });
358
+ * ```
359
+ *
360
+ * The `--trace-warnings` command-line flag can be used to display the
361
+ * stack trace for such warnings.
362
+ *
363
+ * The emitted warning can be inspected with `process.on('warning')` and will
364
+ * have the additional `emitter`, `type`, and `count` properties, referring to
365
+ * the event emitter instance, the event's name and the number of attached
366
+ * listeners, respectively.
367
+ * Its `name` property is set to `'MaxListenersExceededWarning'`.
368
+ * @since v0.11.2
369
+ */
328
370
  static defaultMaxListeners: number;
329
371
  }
330
372
  import internal = require('node:events');
node/ts4.8/fs.d.ts CHANGED
@@ -149,12 +149,38 @@ declare module 'fs' {
149
149
  }
150
150
  export interface StatsFs extends StatsFsBase<number> {}
151
151
  /**
152
- * Provides information about a mounted file system
152
+ * Provides information about a mounted file system.
153
153
  *
154
- * Objects returned from {@link statfs} and {@link statfsSync} are of this type.
155
- * If `bigint` in the `options` passed to those methods is true, the numeric values
156
- * will be `bigint` instead of `number`.
157
- * @since v18.15.0
154
+ * Objects returned from {@link statfs} and its synchronous counterpart are of
155
+ * this type. If `bigint` in the `options` passed to those methods is `true`, the
156
+ * numeric values will be `bigint` instead of `number`.
157
+ *
158
+ * ```console
159
+ * StatFs {
160
+ * type: 1397114950,
161
+ * bsize: 4096,
162
+ * blocks: 121938943,
163
+ * bfree: 61058895,
164
+ * bavail: 61058895,
165
+ * files: 999,
166
+ * ffree: 1000000
167
+ * }
168
+ * ```
169
+ *
170
+ * `bigint` version:
171
+ *
172
+ * ```console
173
+ * StatFs {
174
+ * type: 1397114950n,
175
+ * bsize: 4096n,
176
+ * blocks: 121938943n,
177
+ * bfree: 61058895n,
178
+ * bavail: 61058895n,
179
+ * files: 999n,
180
+ * ffree: 1000000n
181
+ * }
182
+ * ```
183
+ * @since v19.6.0, v18.15.0
158
184
  */
159
185
  export class StatsFs {}
160
186
  export interface BigIntStatsFs extends StatsFsBase<bigint> {}
@@ -214,6 +240,11 @@ declare module 'fs' {
214
240
  * @since v10.10.0
215
241
  */
216
242
  name: string;
243
+ /**
244
+ * The base path that this `fs.Dirent` object refers to.
245
+ * @since v20.1.0
246
+ */
247
+ path: string;
217
248
  }
218
249
  /**
219
250
  * A class representing a directory stream.
@@ -1,22 +1,28 @@
1
1
  /**
2
- * The `readline/promise` module provides an API for reading lines of input from a Readable stream one line at a time.
3
- *
4
- * @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/readline/promises.js)
5
2
  * @since v17.0.0
3
+ * @experimental
6
4
  */
7
5
  declare module 'readline/promises' {
8
6
  import { Interface as _Interface, ReadLineOptions, Completer, AsyncCompleter, Direction } from 'node:readline';
9
7
  import { Abortable } from 'node:events';
8
+ /**
9
+ * Instances of the `readlinePromises.Interface` class are constructed using the`readlinePromises.createInterface()` method. Every instance is associated with a
10
+ * single `input` `Readable` stream and a single `output` `Writable` stream.
11
+ * The `output` stream is used to print prompts for user input that arrives on,
12
+ * and is read from, the `input` stream.
13
+ * @since v17.0.0
14
+ */
10
15
  class Interface extends _Interface {
11
16
  /**
12
- * The rl.question() method displays the query by writing it to the output, waits for user input to be provided on input,
13
- * then invokes the callback function passing the provided input as the first argument.
17
+ * The `rl.question()` method displays the `query` by writing it to the `output`,
18
+ * waits for user input to be provided on `input`, then invokes the `callback`function passing the provided input as the first argument.
14
19
  *
15
- * When called, rl.question() will resume the input stream if it has been paused.
20
+ * When called, `rl.question()` will resume the `input` stream if it has been
21
+ * paused.
16
22
  *
17
- * If the readlinePromises.Interface was created with output set to null or undefined the query is not written.
23
+ * If the `Interface` was created with `output` set to `null` or`undefined` the `query` is not written.
18
24
  *
19
- * If the question is called after rl.close(), it returns a rejected promise.
25
+ * If the question is called after `rl.close()`, it returns a rejected promise.
20
26
  *
21
27
  * Example usage:
22
28
  *
@@ -25,7 +31,7 @@ declare module 'readline/promises' {
25
31
  * console.log(`Oh, so your favorite food is ${answer}`);
26
32
  * ```
27
33
  *
28
- * Using an AbortSignal to cancel a question.
34
+ * Using an `AbortSignal` to cancel a question.
29
35
  *
30
36
  * ```js
31
37
  * const signal = AbortSignal.timeout(10_000);
@@ -37,13 +43,16 @@ declare module 'readline/promises' {
37
43
  * const answer = await rl.question('What is your favorite food? ', { signal });
38
44
  * console.log(`Oh, so your favorite food is ${answer}`);
39
45
  * ```
40
- *
41
46
  * @since v17.0.0
42
- * @param query A statement or query to write to output, prepended to the prompt.
47
+ * @param query A statement or query to write to `output`, prepended to the prompt.
48
+ * @return A promise that is fulfilled with the user's input in response to the `query`.
43
49
  */
44
50
  question(query: string): Promise<string>;
45
51
  question(query: string, options: Abortable): Promise<string>;
46
52
  }
53
+ /**
54
+ * @since v17.0.0
55
+ */
47
56
  class Readline {
48
57
  /**
49
58
  * @param stream A TTY stream.
@@ -55,46 +64,66 @@ declare module 'readline/promises' {
55
64
  }
56
65
  );
57
66
  /**
58
- * The `rl.clearLine()` method adds to the internal list of pending action an action that clears current line of the associated `stream` in a specified direction identified by `dir`.
59
- * Call `rl.commit()` to see the effect of this method, unless `autoCommit: true` was passed to the constructor.
67
+ * The `rl.clearLine()` method adds to the internal list of pending action an
68
+ * action that clears current line of the associated `stream` in a specified
69
+ * direction identified by `dir`.
70
+ * Call `rl.commit()` to see the effect of this method, unless `autoCommit: true`was passed to the constructor.
71
+ * @since v17.0.0
72
+ * @return this
60
73
  */
61
74
  clearLine(dir: Direction): this;
62
75
  /**
63
- * The `rl.clearScreenDown()` method adds to the internal list of pending action an action that clears the associated `stream` from the current position of the cursor down.
64
- * Call `rl.commit()` to see the effect of this method, unless `autoCommit: true` was passed to the constructor.
76
+ * The `rl.clearScreenDown()` method adds to the internal list of pending action an
77
+ * action that clears the associated stream from the current position of the
78
+ * cursor down.
79
+ * Call `rl.commit()` to see the effect of this method, unless `autoCommit: true`was passed to the constructor.
80
+ * @since v17.0.0
81
+ * @return this
65
82
  */
66
83
  clearScreenDown(): this;
67
84
  /**
68
- * The `rl.commit()` method sends all the pending actions to the associated `stream` and clears the internal list of pending actions.
85
+ * The `rl.commit()` method sends all the pending actions to the associated`stream` and clears the internal list of pending actions.
86
+ * @since v17.0.0
69
87
  */
70
88
  commit(): Promise<void>;
71
89
  /**
72
- * The `rl.cursorTo()` method adds to the internal list of pending action an action that moves cursor to the specified position in the associated `stream`.
73
- * Call `rl.commit()` to see the effect of this method, unless `autoCommit: true` was passed to the constructor.
90
+ * The `rl.cursorTo()` method adds to the internal list of pending action an action
91
+ * that moves cursor to the specified position in the associated `stream`.
92
+ * Call `rl.commit()` to see the effect of this method, unless `autoCommit: true`was passed to the constructor.
93
+ * @since v17.0.0
94
+ * @return this
74
95
  */
75
96
  cursorTo(x: number, y?: number): this;
76
97
  /**
77
- * The `rl.moveCursor()` method adds to the internal list of pending action an action that moves the cursor relative to its current position in the associated `stream`.
78
- * Call `rl.commit()` to see the effect of this method, unless autoCommit: true was passed to the constructor.
98
+ * The `rl.moveCursor()` method adds to the internal list of pending action an
99
+ * action that moves the cursor _relative_ to its current position in the
100
+ * associated `stream`.
101
+ * Call `rl.commit()` to see the effect of this method, unless `autoCommit: true`was passed to the constructor.
102
+ * @since v17.0.0
103
+ * @return this
79
104
  */
80
105
  moveCursor(dx: number, dy: number): this;
81
106
  /**
82
- * The `rl.rollback()` method clears the internal list of pending actions without sending it to the associated `stream`.
107
+ * The `rl.rollback` methods clears the internal list of pending actions without
108
+ * sending it to the associated `stream`.
109
+ * @since v17.0.0
110
+ * @return this
83
111
  */
84
112
  rollback(): this;
85
113
  }
86
114
  /**
87
- * The `readlinePromises.createInterface()` method creates a new `readlinePromises.Interface` instance.
115
+ * The `readlinePromises.createInterface()` method creates a new `readlinePromises.Interface`instance.
88
116
  *
89
117
  * ```js
90
118
  * const readlinePromises = require('node:readline/promises');
91
119
  * const rl = readlinePromises.createInterface({
92
120
  * input: process.stdin,
93
- * output: process.stdout
121
+ * output: process.stdout,
94
122
  * });
95
123
  * ```
96
124
  *
97
- * Once the `readlinePromises.Interface` instance is created, the most common case is to listen for the `'line'` event:
125
+ * Once the `readlinePromises.Interface` instance is created, the most common case
126
+ * is to listen for the `'line'` event:
98
127
  *
99
128
  * ```js
100
129
  * rl.on('line', (line) => {
@@ -102,42 +131,13 @@ declare module 'readline/promises' {
102
131
  * });
103
132
  * ```
104
133
  *
105
- * If `terminal` is `true` for this instance then the `output` stream will get the best compatibility if it defines an `output.columns` property,
106
- * and emits a `'resize'` event on the `output`, if or when the columns ever change (`process.stdout` does this automatically when it is a TTY).
107
- *
108
- * ## Use of the `completer` function
109
- *
110
- * The `completer` function takes the current line entered by the user as an argument, and returns an `Array` with 2 entries:
111
- *
112
- * - An Array with matching entries for the completion.
113
- * - The substring that was used for the matching.
114
- *
115
- * For instance: `[[substr1, substr2, ...], originalsubstring]`.
116
- *
117
- * ```js
118
- * function completer(line) {
119
- * const completions = '.help .error .exit .quit .q'.split(' ');
120
- * const hits = completions.filter((c) => c.startsWith(line));
121
- * // Show all completions if none found
122
- * return [hits.length ? hits : completions, line];
123
- * }
124
- * ```
125
- *
126
- * The `completer` function can also returns a `Promise`, or be asynchronous:
127
- *
128
- * ```js
129
- * async function completer(linePartial) {
130
- * await someAsyncWork();
131
- * return [['123'], linePartial];
132
- * }
133
- * ```
134
+ * If `terminal` is `true` for this instance then the `output` stream will get
135
+ * the best compatibility if it defines an `output.columns` property and emits
136
+ * a `'resize'` event on the `output` if or when the columns ever change
137
+ * (`process.stdout` does this automatically when it is a TTY).
138
+ * @since v17.0.0
134
139
  */
135
- function createInterface(
136
- input: NodeJS.ReadableStream,
137
- output?: NodeJS.WritableStream,
138
- completer?: Completer | AsyncCompleter,
139
- terminal?: boolean,
140
- ): Interface;
140
+ function createInterface(input: NodeJS.ReadableStream, output?: NodeJS.WritableStream, completer?: Completer | AsyncCompleter, terminal?: boolean): Interface;
141
141
  function createInterface(options: ReadLineOptions): Interface;
142
142
  }
143
143
  declare module 'node:readline/promises' {
node/ts4.8/readline.d.ts CHANGED
@@ -35,7 +35,6 @@
35
35
  declare module 'readline' {
36
36
  import { Abortable, EventEmitter } from 'node:events';
37
37
  import * as promises from 'node:readline/promises';
38
-
39
38
  export { promises };
40
39
  export interface Key {
41
40
  sequence?: string | undefined;
@@ -74,7 +73,7 @@ declare module 'readline' {
74
73
  * const showResults = debounce(() => {
75
74
  * console.log(
76
75
  * '\n',
77
- * values.filter((val) => val.startsWith(rl.line)).join(' ')
76
+ * values.filter((val) => val.startsWith(rl.line)).join(' '),
78
77
  * );
79
78
  * }, 300);
80
79
  * process.stdin.on('keypress', (c, k) => {
@@ -100,7 +99,7 @@ declare module 'readline' {
100
99
  * > Instances of the `readline.Interface` class are constructed using the
101
100
  * > `readline.createInterface()` method.
102
101
  *
103
- * @see https://nodejs.org/dist/latest-v10.x/docs/api/readline.html#readline_class_interface
102
+ * @see https://nodejs.org/dist/latest-v20.x/docs/api/readline.html#class-interfaceconstructor
104
103
  */
105
104
  protected constructor(input: NodeJS.ReadableStream, output?: NodeJS.WritableStream, completer?: Completer | AsyncCompleter, terminal?: boolean);
106
105
  /**
@@ -109,12 +108,12 @@ declare module 'readline' {
109
108
  * > Instances of the `readline.Interface` class are constructed using the
110
109
  * > `readline.createInterface()` method.
111
110
  *
112
- * @see https://nodejs.org/dist/latest-v10.x/docs/api/readline.html#readline_class_interface
111
+ * @see https://nodejs.org/dist/latest-v20.x/docs/api/readline.html#class-interfaceconstructor
113
112
  */
114
113
  protected constructor(options: ReadLineOptions);
115
114
  /**
116
115
  * The `rl.getPrompt()` method returns the current prompt used by `rl.prompt()`.
117
- * @since v15.3.0
116
+ * @since v15.3.0, v14.17.0
118
117
  * @return the current prompt string
119
118
  */
120
119
  getPrompt(): string;
@@ -124,13 +123,13 @@ declare module 'readline' {
124
123
  */
125
124
  setPrompt(prompt: string): void;
126
125
  /**
127
- * The `rl.prompt()` method writes the `readline.Interface` instances configured`prompt` to a new line in `output` in order to provide a user with a new
126
+ * The `rl.prompt()` method writes the `Interface` instances configured`prompt` to a new line in `output` in order to provide a user with a new
128
127
  * location at which to provide input.
129
128
  *
130
129
  * When called, `rl.prompt()` will resume the `input` stream if it has been
131
130
  * paused.
132
131
  *
133
- * If the `readline.Interface` was created with `output` set to `null` or`undefined` the prompt is not written.
132
+ * If the `Interface` was created with `output` set to `null` or`undefined` the prompt is not written.
134
133
  * @since v0.1.98
135
134
  * @param preserveCursor If `true`, prevents the cursor placement from being reset to `0`.
136
135
  */
@@ -142,12 +141,14 @@ declare module 'readline' {
142
141
  * When called, `rl.question()` will resume the `input` stream if it has been
143
142
  * paused.
144
143
  *
145
- * If the `readline.Interface` was created with `output` set to `null` or`undefined` the `query` is not written.
144
+ * If the `Interface` was created with `output` set to `null` or`undefined` the `query` is not written.
146
145
  *
147
146
  * The `callback` function passed to `rl.question()` does not follow the typical
148
147
  * pattern of accepting an `Error` object or `null` as the first argument.
149
148
  * The `callback` is called with the provided answer as the only argument.
150
149
  *
150
+ * An error will be thrown if calling `rl.question()` after `rl.close()`.
151
+ *
151
152
  * Example usage:
152
153
  *
153
154
  * ```js
@@ -172,25 +173,6 @@ declare module 'readline' {
172
173
  *
173
174
  * setTimeout(() => ac.abort(), 10000);
174
175
  * ```
175
- *
176
- * If this method is invoked as it's util.promisify()ed version, it returns a
177
- * Promise that fulfills with the answer. If the question is canceled using
178
- * an `AbortController` it will reject with an `AbortError`.
179
- *
180
- * ```js
181
- * const util = require('util');
182
- * const question = util.promisify(rl.question).bind(rl);
183
- *
184
- * async function questionExample() {
185
- * try {
186
- * const answer = await question('What is you favorite food? ');
187
- * console.log(`Oh, so your favorite food is ${answer}`);
188
- * } catch (err) {
189
- * console.error('Question rejected', err);
190
- * }
191
- * }
192
- * questionExample();
193
- * ```
194
176
  * @since v0.3.3
195
177
  * @param query A statement or query to write to `output`, prepended to the prompt.
196
178
  * @param callback A callback function that is invoked with the user's input in response to the `query`.
@@ -201,7 +183,7 @@ declare module 'readline' {
201
183
  * The `rl.pause()` method pauses the `input` stream, allowing it to be resumed
202
184
  * later if necessary.
203
185
  *
204
- * Calling `rl.pause()` does not immediately pause other events (including`'line'`) from being emitted by the `readline.Interface` instance.
186
+ * Calling `rl.pause()` does not immediately pause other events (including`'line'`) from being emitted by the `Interface` instance.
205
187
  * @since v0.3.4
206
188
  */
207
189
  pause(): this;
@@ -211,12 +193,12 @@ declare module 'readline' {
211
193
  */
212
194
  resume(): this;
213
195
  /**
214
- * The `rl.close()` method closes the `readline.Interface` instance and
196
+ * The `rl.close()` method closes the `Interface` instance and
215
197
  * relinquishes control over the `input` and `output` streams. When called,
216
198
  * the `'close'` event will be emitted.
217
199
  *
218
200
  * Calling `rl.close()` does not immediately stop other events (including `'line'`)
219
- * from being emitted by the `readline.Interface` instance.
201
+ * from being emitted by the `Interface` instance.
220
202
  * @since v0.1.98
221
203
  */
222
204
  close(): void;
@@ -231,7 +213,7 @@ declare module 'readline' {
231
213
  * When called, `rl.write()` will resume the `input` stream if it has been
232
214
  * paused.
233
215
  *
234
- * If the `readline.Interface` was created with `output` set to `null` or`undefined` the `data` and `key` are not written.
216
+ * If the `Interface` was created with `output` set to `null` or`undefined` the `data` and `key` are not written.
235
217
  *
236
218
  * ```js
237
219
  * rl.write('Delete this!');
@@ -351,10 +333,10 @@ declare module 'readline' {
351
333
  * The `readline.createInterface()` method creates a new `readline.Interface`instance.
352
334
  *
353
335
  * ```js
354
- * const readline = require('readline');
336
+ * const readline = require('node:readline');
355
337
  * const rl = readline.createInterface({
356
338
  * input: process.stdin,
357
- * output: process.stdout
339
+ * output: process.stdout,
358
340
  * });
359
341
  * ```
360
342
  *
@@ -373,14 +355,8 @@ declare module 'readline' {
373
355
  * (`process.stdout` does this automatically when it is a TTY).
374
356
  *
375
357
  * When creating a `readline.Interface` using `stdin` as input, the program
376
- * will not terminate until it receives `EOF` (Ctrl+D on
377
- * Linux/macOS, Ctrl+Z followed by Return on
378
- * Windows).
379
- * If you want your application to exit without waiting for user input, you can `unref()` the standard input stream:
380
- *
381
- * ```js
382
- * process.stdin.unref();
383
- * ```
358
+ * will not terminate until it receives an [EOF character](https://en.wikipedia.org/wiki/End-of-file#EOF_character). To exit without
359
+ * waiting for user input, call `process.stdin.unref()`.
384
360
  * @since v0.1.98
385
361
  */
386
362
  export function createInterface(input: NodeJS.ReadableStream, output?: NodeJS.WritableStream, completer?: Completer | AsyncCompleter, terminal?: boolean): Interface;
@@ -539,109 +515,6 @@ declare module 'readline' {
539
515
  /**
540
516
  * The `readline.moveCursor()` method moves the cursor _relative_ to its current
541
517
  * position in a given `TTY` `stream`.
542
- *
543
- * ## Example: Tiny CLI
544
- *
545
- * The following example illustrates the use of `readline.Interface` class to
546
- * implement a small command-line interface:
547
- *
548
- * ```js
549
- * const readline = require('readline');
550
- * const rl = readline.createInterface({
551
- * input: process.stdin,
552
- * output: process.stdout,
553
- * prompt: 'OHAI> '
554
- * });
555
- *
556
- * rl.prompt();
557
- *
558
- * rl.on('line', (line) => {
559
- * switch (line.trim()) {
560
- * case 'hello':
561
- * console.log('world!');
562
- * break;
563
- * default:
564
- * console.log(`Say what? I might have heard '${line.trim()}'`);
565
- * break;
566
- * }
567
- * rl.prompt();
568
- * }).on('close', () => {
569
- * console.log('Have a great day!');
570
- * process.exit(0);
571
- * });
572
- * ```
573
- *
574
- * ## Example: Read file stream line-by-Line
575
- *
576
- * A common use case for `readline` is to consume an input file one line at a
577
- * time. The easiest way to do so is leveraging the `fs.ReadStream` API as
578
- * well as a `for await...of` loop:
579
- *
580
- * ```js
581
- * const fs = require('fs');
582
- * const readline = require('readline');
583
- *
584
- * async function processLineByLine() {
585
- * const fileStream = fs.createReadStream('input.txt');
586
- *
587
- * const rl = readline.createInterface({
588
- * input: fileStream,
589
- * crlfDelay: Infinity
590
- * });
591
- * // Note: we use the crlfDelay option to recognize all instances of CR LF
592
- * // ('\r\n') in input.txt as a single line break.
593
- *
594
- * for await (const line of rl) {
595
- * // Each line in input.txt will be successively available here as `line`.
596
- * console.log(`Line from file: ${line}`);
597
- * }
598
- * }
599
- *
600
- * processLineByLine();
601
- * ```
602
- *
603
- * Alternatively, one could use the `'line'` event:
604
- *
605
- * ```js
606
- * const fs = require('fs');
607
- * const readline = require('readline');
608
- *
609
- * const rl = readline.createInterface({
610
- * input: fs.createReadStream('sample.txt'),
611
- * crlfDelay: Infinity
612
- * });
613
- *
614
- * rl.on('line', (line) => {
615
- * console.log(`Line from file: ${line}`);
616
- * });
617
- * ```
618
- *
619
- * Currently, `for await...of` loop can be a bit slower. If `async` / `await`flow and speed are both essential, a mixed approach can be applied:
620
- *
621
- * ```js
622
- * const { once } = require('events');
623
- * const { createReadStream } = require('fs');
624
- * const { createInterface } = require('readline');
625
- *
626
- * (async function processLineByLine() {
627
- * try {
628
- * const rl = createInterface({
629
- * input: createReadStream('big-file.txt'),
630
- * crlfDelay: Infinity
631
- * });
632
- *
633
- * rl.on('line', (line) => {
634
- * // Process the line.
635
- * });
636
- *
637
- * await once(rl, 'close');
638
- *
639
- * console.log('File processed.');
640
- * } catch (err) {
641
- * console.error(err);
642
- * }
643
- * })();
644
- * ```
645
518
  * @since v0.7.7
646
519
  * @param callback Invoked once the operation completes.
647
520
  * @return `false` if `stream` wishes for the calling code to wait for the `'drain'` event to be emitted before continuing to write additional data; otherwise `true`.