MCPcopy Create free account
hub / github.com/denoland/std / StreamLineReader

Class StreamLineReader

csv/parse_stream.ts:68–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

66}
67
68class 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
95function stripLastCR(s: string): string {
96 return s.endsWith("\r") ? s.slice(0, -1) : s;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected