问题
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 infs.js
)? - Where can I find the source code of
binding.open
? Is it Javascript code or c/c++ code?
回答1:
process.binding()
is an internal API used by node to get a reference to the various core C++ bindings.'fs'
inprocess.binding('fs')
is a reference to the C++ binding (src/node_file.cc in the node source tree) for thefs
module.- As mentioned,
process.binding()
references C++ bindings, so in this casebinding.open()
is exported here and defined here.
来源:https://stackoverflow.com/questions/37916949/what-is-process-bindingfs-in-fs-js