我正在读取一个正在写入的文件。所以我有:
const readStream = fs.createReadStream(file, {start:0});
根据我的测试,看起来 fs.createReadStream
会为 {end:number} 设置一个值,其中读取流的结尾是文件的当前结尾。然而理论上,当流从文件中读取数据时,它可以一直读取到文件的新末尾(因为在读取过程中正在写入新数据)。
有谁确切知道这是如何实现的?
最佳答案
您可以使用 autoClose: false
来防止自动关闭:
https://nodejs.org/api/fs.html#fs_fs_createreadstream_path_options
If autoClose is false, then the file descriptor won't be closed, even if there's an error. It is the application's responsibility to close it and make sure there's no file descriptor leak. If autoClose is set to true (default behavior), on 'error' or 'end' the file descriptor will be closed automatically.
关于node.js - `fs.createReadStream` 是否将默认结束值设置为文件的当前结尾?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57064325/