Method Description:
Open the file in an asynchronous fashion.
In a POSIX system, path is assumed to exist by default (even if the files under that path do not exist)
The flag identity may or may not be running under the network file system.
Grammar:
Copy Code code as follows:
Fs.open (path, flags, [mode], [Callback (ERR,FD)])
Because this method belongs to the FS module, it is necessary to introduce FS module (VAR fs= require ("FS") before use.
Receive parameters:
Path file paths
Flags can be the following values
Copy Code code as follows:
' R '-opens the file in read mode.
' r+ '-opens the file in read-write mode.
' RS '-open and read files using synchronous mode. Indicates that the operating system ignores the local file system cache.
' Rs+ '-opens synchronously, reads and writes to the file.
Note: This is not a blocking operation that turns Fs.open into a synchronous mode. If you want to sync mode, use Fs.opensync ().
' W '-opens the file in read mode and creates it if the file does not exist
' WX '-and ' W ' mode, return failure if file exists
' w+ '-opens the file in read-write mode and creates it if the file does not exist
' wx+ '-like ' w+ ' mode, return failure if file exists
' A '-opens the file in Append mode and creates if the file does not exist
' Ax '-and ' a ' mode, return failure if file exists
' A + '-opens the file in read Append mode, and creates it if the file does not exist
' ax+ '-as in ' A + ' mode, return failure if file exists
Mode to set permissions on files when you create them, default 0666
The callback callback function passes a file descriptor fd, and an exception err
Example:
Copy Code code as follows:
var fs = require (' FS ');
Fs.open ('/path/demo1.txt ', ' a ', function (err, FD) {
if (err) {
throw err;
}
Fs.futimes (FD, 1388648322, 1388648322, function (err) {
if (err) {
throw err;
}
Console.log (' futimes complete ');
Fs.close (FD, function () {
Console.log (' done ');
});
});
});
Source:
Copy Code code as follows:
Fs.open = function (path, flags, mode, callback) {
callback = Makecallback (Arguments[arguments.length-1]);
mode = Modenum (mode, 438/*=0666*/);
if (!nullcheck (path, callback)) return;
Binding.open (path), Pathmodule._makelong
Stringtoflags (Flags),
Mode
callback);
};