gpt4 book ai didi

node.js - `fs.createReadStream` 是否将默认结束值设置为文件的当前结尾?

转载 作者:搜寻专家 更新时间:2023-10-31 23:49:57 24 4
gpt4 key购买 nike

我正在读取一个正在写入的文件。所以我有:

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com