There are many functions related to the operation of the system. Can be divided into two categories first.
The class is asynchronous + callback. The class is synchronized.
In this case only to the asynchronous collation, synchronization only need to be followed by the function name plus sync
1. The first is a class of most conventional reading and writing functions, function name and form, should be originated from the C language.
Copy Code code as follows:
Fs.open (file path, read-write identity, [file mode value, 666], callback function (err, file handle fd));
Fs.read (file handle FD, written buffer,offset,length,position, callback function (err, bytesread, buffer));
Fs.write (file handle FD, read Buffer,offset,length,position, callback function (Err,byteswritten,buffer));
Fs.close (file handle, callback function)
Fs.truncate (file handle, truncation length, callback function);
Fs.fsync (file handle, callback function);
2. Directly to read and write documents, it is more convenient to use.
Copy Code code as follows:
Fs.readfile (filename, encoding, callback function (Err,data));
Fs.writefile (filename, data, encoding, callback function (err));
Fs.appendfile (filename, data, encoding, callback function (err));
3. Other common file operation
Copy Code code as follows:
To determine whether a file exists
Fs.exists (file path, callback (if present));
Renaming
Fs.rename (old filename, new file name, callback function);
File owner Change
Fs.chown (filename, Uid,gid, callback function);/fs.fchown (file handle Fd,uid,gid, callback function);/fs.lchown (link path, Uid,gid, callback function);
File permission changes
Fs.chmod (filename, mode, callback function);/fs.fchmod (file handle, mode, callback function);/fs.lchmod (link path, mode, callback function);
File information
Fs.stat (file path, callback function (Err.fs.Stats object));/fs.fstat (file handle FD, callback function (Err.fs.Stats object))/fs.lstat (link path, callback function (Err.fs.Stats object)) ;
File time
Fs.utimes (file path, access time, new time, callback function);/fs.futimes (file handle, access time, new time, callback function);
Monitoring files
Fs.watchfile (filename, [Options],listener_callback (Stats of current file, stats before change));
Fs.unwatchfile (filename);
4. Directory operation
Copy Code code as follows:
Fs.mkdir (path, permission mode/777, callback function);
Fs.rmdir (path, callback function);
Fs.readdir (Path, callback function (Err,filenamearray));
5. Linked file operation
Copy Code code as follows:
Create a link
Fs.link (Srcpath, Dstpath, [callback])
Fs.symlink (destination, path, [type], [callback])
Read the path that the link points to
Fs.readlink (Path, [Callback (ERR,LINKSTR)])
Fs.unlink (Path,[callback]);