场景调用fs.close是必要的 [英] What the scenario call fs.close is necessary

查看:75
本文介绍了场景调用fs.close是必要的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到更多关于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 fd 或者继续流并在发送完所有数据之后结束。



但是,如果您打电话给 fs.open 或其他给出 fd fs.close fd 给你。


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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆