考虑一下换语言? ry 大神新作 Deno,有个现成的函数直接对应你的需求
https://deno.land/std@0.83.0/io#readstringdelim
----------
readStringDelim
Read reader[like file] chunk by chunk, splitting based on delimiter.
import { readStringDelim } from "https://deno.land/std@0.83.0/io/mod.ts";
import * as path from "https://deno.land/std@0.83.0/path/mod.ts";
const filename = path.join(Deno.cwd(), "std/io/
README.md");
let fileReader = await Deno.open(filename);
for await (let line of readStringDelim(fileReader, "\n")) {
console.log(line);
}
Output:
# std/io
## readLines
```ts
import * as path from "https://deno.land/std@0.83.0/path/mod.ts";
## Rest of the file