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:
process.binding('fs')
mean? fs
here (We already in fs.js
)?binding.open
? Is it Javascript code or c/c++ code?js fs module provides two different functions for writing files: writeFile and writeFileSync . Both functions take a file path and data as arguments, and write the data to the specified file. However, there is a key difference between the two functions: writeFile is asynchronous, while writeFileSync is synchronous.
The fs. copyFile() method is used to asynchronously copy a file from the source path to destination path. By default, Node. js will overwrite the file if it already exists at the given destination.
Commonly used features of the fs module include fs. readFile to read data from a file, fs. writeFile to write data to a file and replace the file if it already exists, fs. watchFile to get notified of changes, and fs.
To delete a file in Node. js, Node FS unlink(path, callback) can be used for asynchronous file operation and unlinkSync(path) can be used for synchronous file operation.
process.binding()
is an internal API used by node to get a reference to the various core C++ bindings.'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.process.binding()
references C++ bindings, so in this case binding.open()
is exported here and defined here.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With