| 66 | } |
| 67 | |
| 68 | class StreamLineReader implements LineReader { |
| 69 | #reader: ReadableStreamDefaultReader<string>; |
| 70 | #done = false; |
| 71 | constructor(reader: ReadableStreamDefaultReader<string>) { |
| 72 | this.#reader = reader; |
| 73 | } |
| 74 | |
| 75 | async readLine(): Promise<string | null> { |
| 76 | const { value, done } = await this.#reader.read(); |
| 77 | if (done) { |
| 78 | this.#done = true; |
| 79 | return null; |
| 80 | } else { |
| 81 | // NOTE: Remove trailing CR for compatibility with golang's `encoding/csv` |
| 82 | return stripLastCR(value!); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | isEOF(): boolean { |
| 87 | return this.#done; |
| 88 | } |
| 89 | |
| 90 | cancel() { |
| 91 | this.#reader.cancel(); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | function stripLastCR(s: string): string { |
| 96 | return s.endsWith("\r") ? s.slice(0, -1) : s; |
nothing calls this directly
no outgoing calls
no test coverage detected