What is `process.binding('fs')` in `fs.js`? [duplicate]

有些话、适合烂在心里 提交于 2019-12-07 00:21:10

问题


I see in top of the fs.js there is a process.binding('fs').

https://github.com/nodejs/node/blob/master/lib/fs.js#L10:

const binding = process.binding('fs');

And then, it's used as:

binding.open(pathModule._makeLong(path),
           stringToFlags(flag),
           0o666,
           req);

(In https://github.com/nodejs/node/blob/master/lib/fs.js#L303-L306)

My question is:

  • What does process.binding('fs') mean?
  • What's fs here (We already in fs.js)?
  • Where can I find the source code of binding.open? Is it Javascript code or c/c++ code?

回答1:


  1. process.binding() is an internal API used by node to get a reference to the various core C++ bindings.
  2. 'fs' in process.binding('fs') is a reference to the C++ binding (src/node_file.cc in the node source tree) for the fs module.
  3. As mentioned, process.binding() references C++ bindings, so in this case binding.open() is exported here and defined here.


来源:https://stackoverflow.com/questions/37916949/what-is-process-bindingfs-in-fs-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!