Construct a new instance. * * @param options Options for the stream.
(options?: T)
| 368 | * @param options Options for the stream. |
| 369 | */ |
| 370 | constructor(options?: T) { |
| 371 | this.#options = { |
| 372 | ...options, |
| 373 | separator: options?.separator ?? ",", |
| 374 | trimLeadingSpace: options?.trimLeadingSpace ?? false, |
| 375 | }; |
| 376 | |
| 377 | if ( |
| 378 | this.#options.fieldsPerRecord === undefined || |
| 379 | this.#options.fieldsPerRecord < 0 |
| 380 | ) { |
| 381 | this.#fieldsPerRecord = "ANY"; |
| 382 | } else if (this.#options.fieldsPerRecord === 0) { |
| 383 | this.#fieldsPerRecord = "UNINITIALIZED"; |
| 384 | } else { |
| 385 | // TODO: Should we check if it's a valid integer? |
| 386 | this.#fieldsPerRecord = this.#options.fieldsPerRecord; |
| 387 | } |
| 388 | |
| 389 | this.#lines = new TextDelimiterStream("\n"); |
| 390 | this.#lineReader = new StreamLineReader(this.#lines.readable.getReader()); |
| 391 | this.#readable = new ReadableStream({ |
| 392 | pull: (controller) => this.#pull(controller), |
| 393 | cancel: () => this.#lineReader.cancel(), |
| 394 | }); |
| 395 | } |
| 396 | |
| 397 | async #pull( |
| 398 | controller: ReadableStreamDefaultController< |