Description of Fs.open method used in Node.js _node.js

Source: Internet
Author: User

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);
};

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.