Object built-in object

ObjectFileHandle

file handle object

1
var fd = fs.open('test.txt');

inheritance relationship

member properties

fd

Integer, query the current file descriptor

1
readonly Integer FileHandle.fd;

member function

chmod

Query the access permissions of the current file. Windows does not support this method.

1
FileHandle.chmod(Integer mode) async;

Call parameters:

  • mode: Integer, specifies the set access permissions

stat

Query basic information of the current file

1
Stat FileHandle.stat() async;

Return results:

  • Stat, returns the basic information of the file

read

Read the file content according to the file descriptor

1 2 3 4
Integer FileHandle.read(Buffer buffer, Integer offset = 0, Integer length = 0, Integer position = -1) async;

Call parameters:

  • buffer:Buffer, the read result is written toBufferobject
  • offset: Integer,BufferWrite offset, default is 0
  • length: Integer, the number of bytes read from the file, the default is 0
  • position: Integer, file reading position, default is the current file position

Return results:

  • Integer, the actual number of bytes read

write

Write content to the file according to the file descriptor

1 2 3 4
Integer FileHandle.write(Buffer buffer, Integer offset = 0, Integer length = -1, Integer position = -1) async;

Call parameters:

  • buffer:Buffer, to be writtenBufferobject
  • offset: Integer,BufferData read offset, default is 0
  • length: Integer, the number of bytes written to the file, the default is -1
  • position: Integer, file writing location, default is the current file location

Return results:

  • Integer, the actual number of bytes written

Write content to the file according to the file descriptor

1 2 3
Integer FileHandle.write(String string, Integer position = -1, String encoding = "utf8") async;

Call parameters:

  • string: String, the string to be written
  • position: Integer, file writing location, default is the current file location
  • encoding: String, specifies the decoding method, the default decoding is utf8

Return results:

  • Integer, the actual number of bytes written

close

Close current file handle

1
FileHandle.close() async;

toString

Returns the string representation of the object. Generally, "[Native Object]" is returned. The object can be re-implemented according to its own characteristics.

1
String FileHandle.toString();

Return results:

  • String, returns the string representation of the object

toJSON

Returns a JSON format representation of the object, generally returning a collection of readable properties defined by the object.

1
Value FileHandle.toJSON(String key = "");

Call parameters:

  • key: String, not used

Return results:

  • Value, returns a value containing JSON serializable