(
controller: ReadableStreamDefaultController<
string[] | Record<string, string | unknown>
>,
)
| 395 | } |
| 396 | |
| 397 | async #pull( |
| 398 | controller: ReadableStreamDefaultController< |
| 399 | string[] | Record<string, string | unknown> |
| 400 | >, |
| 401 | ): Promise<void> { |
| 402 | const line = await this.#lineReader.readLine(); |
| 403 | if (line === "") { |
| 404 | // Found an empty line |
| 405 | this.#zeroBasedLineIndex++; |
| 406 | return this.#pull(controller); |
| 407 | } |
| 408 | if (line === null) { |
| 409 | // Reached to EOF |
| 410 | controller.close(); |
| 411 | this.#lineReader.cancel(); |
| 412 | return; |
| 413 | } |
| 414 | |
| 415 | const record = await parseRecord( |
| 416 | line, |
| 417 | this.#lineReader, |
| 418 | this.#options, |
| 419 | this.#zeroBasedLineIndex, |
| 420 | ); |
| 421 | |
| 422 | if (this.#isFirstRow) { |
| 423 | this.#isFirstRow = false; |
| 424 | if (this.#options.skipFirstRow || this.#options.columns) { |
| 425 | this.#headers = []; |
| 426 | |
| 427 | if (this.#options.skipFirstRow) { |
| 428 | const head = record; |
| 429 | this.#headers = head; |
| 430 | } |
| 431 | |
| 432 | if (this.#options.columns) { |
| 433 | this.#headers = this.#options.columns; |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | if (this.#options.skipFirstRow) { |
| 438 | return this.#pull(controller); |
| 439 | } |
| 440 | |
| 441 | if (this.#fieldsPerRecord === "UNINITIALIZED") { |
| 442 | this.#fieldsPerRecord = record.length; |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | if ( |
| 447 | typeof this.#fieldsPerRecord === "number" && |
| 448 | record.length !== this.#fieldsPerRecord |
| 449 | ) { |
| 450 | throw new SyntaxError( |
| 451 | `Syntax error on line ${ |
| 452 | this.#zeroBasedLineIndex + 1 |
| 453 | }: expected ${this.#fieldsPerRecord} fields but got ${record.length}`, |
| 454 | ); |
no test coverage detected