场景调用fs.close是必要的 [英] What the scenario call fs.close is necessary
问题描述
我找不到更多关于fs.close在nodejs API中解释的问题。
我想知道场景调用fs.close是必要的。
例如:
var fs = require('fs');
fs.writeFile(/ home / a.tex,abc);或者像fs.appendFile(/ home / a.tex,close)
fs.close(); //有必要吗?
如果我不调用fs.close,是否有任何影响?
任何帮助表示赞赏。
您不需要使用 fs.close
code> fs.readFile , fs.writeFile
或 fs.appendFile
因为它们不返回 fd
(文件描述符)。那些打开文件,对其进行操作,然后关闭它。
由 fs.createReadStream
和 fs.createWriteStream $ c $在溪流结束后关闭,但可能会提前关闭。如果你已经暂停了一个流,你必须在流上调用close来关闭
fd
或者继续流并在发送完所有数据之后结束。
但是,如果您打电话给 fs.open
或其他给出 fd $ c $你必须最终得到
给你。 fs.close
I can't find more about fs.close explain in nodejs API. I want to know what the scenario call fs.close is necessary. for example:
var fs = require('fs'); fs.writeFile("/home/a.tex","abc"); or like fs.appendFile("/home/a.tex","close") fs.close(); //is it necessary?
Are there any effects if i don't call fs.close?
Any help is appreciated.
You don't need to use fs.close
after fs.readFile
, fs.writeFile
, or fs.appendFile
as they don't return a fd
(file descriptor). Those open the file, operate on it, and then close it for you.
The streams returned by fs.createReadStream
and fs.createWriteStream
close after the stream ends but may be closed early. If you have paused a stream, you must call close on the stream to close the fd
or resume the stream and let it end after emitting all its data.
But if you call fs.open
or any of the others that give a fd
, you must eventually fs.close
the fd
that you are given.
这篇关于场景调用fs.close是必要的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!