Asynchronously append data to a file, creating the file if it does not exist. The underlying file will not be closed automatically.
The FileHandle
must have been opened for appending.
The data to write. If something other than a Buffer
or Uint8Array
is provided, the value is coerced to a string.
Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
encoding
defaults to 'utf8'
.mode
defaults to 0o666
.flag
defaults to 'a'
.Creates a stream for reading from the file.
Optional
options: CreateReadStreamOptionsOptions for the readable stream
Creates a stream for writing to the file.
Optional
options: CreateWriteStreamOptionsOptions for the writeable stream.
Asynchronously reads data from the file.
The FileHandle
must have been opened for reading.
The buffer that the data will be written to.
Optional
offset: numberThe offset in the buffer at which to start writing.
Optional
length: numberThe number of bytes to read.
Optional
position: null | numberThe offset from the beginning of the file from which data should be read. If null
, data will be read from the current position.
Experimental
Returns a ReadableStream
that may be used to read the files data.
An error will be thrown if this method is called more than once or is called after the FileHandle
is closed or closing.
While the ReadableStream
will read the file to completion,
it will not close the FileHandle
automatically.
User code must still call the fileHandle.close()
method.
Asynchronously reads the entire contents of a file. The underlying file will not be closed automatically.
The FileHandle
must have been opened for reading.
Optional
_options: { An object that may contain an optional flag.
If a flag is not provided, it defaults to 'r'
.
Optional
flag?: OpenModeAsynchronously reads the entire contents of a file.
If options
is a string, then it specifies the encoding
.
The FileHandle
has to support reading.
If one or more filehandle.read()
calls are made on a file handle and then a filehandle.readFile()
call is made, the data will be read from the current
position till the end of the file. It doesn't always read from the beginning
of the file.
Fulfills upon a successful read with the contents of the file. If no encoding is specified (using options.encoding
), the data is returned as a {Buffer} object. Otherwise, the
data will be a string.
Asynchronous fstat(2) - Get file status.
Optional
opts: StatOptions & { Fulfills with an {fs.Stats} for the file.
Asynchronously change file timestamps of the file.
The last access time. If a string is provided, it will be coerced to number.
The last modified time. If a string is provided, it will be coerced to number.
Asynchronously writes string
to the file.
The FileHandle
must have been opened for writing.
It is unsafe to call write()
multiple times on the same file without waiting for the Promise
to be resolved (or rejected). For this scenario, fs.createWriteStream
is strongly recommended.
Optional
posOrOff: null | numberOptional
lenOrEnc: number | BufferEncodingOptional
position: null | numberWrite buffer
to the file.
The promise is fulfilled with an object containing two properties:
It is unsafe to use filehandle.write()
multiple times on the same file
without waiting for the promise to be fulfilled (or rejected). For this
scenario, use filehandle.createWriteStream()
.
On Linux, positional writes do not work when the file is opened in append mode. The kernel ignores the position argument and always appends the data to the end of the file.
Optional
offset: numberThe start position from within buffer
where the data to write begins.
Optional
length: numberThe number of bytes from buffer
to write.
Optional
position: numberThe offset from the beginning of the file where the data from buffer
should be written. If position
is not a number
, the data will be written at the current
position. See the POSIX pwrite(2) documentation for more detail.
Write buffer
to the file.
The promise is fulfilled with an object containing two properties:
It is unsafe to use filehandle.write()
multiple times on the same file
without waiting for the promise to be fulfilled (or rejected). For this
scenario, use filehandle.createWriteStream()
.
On Linux, positional writes do not work when the file is opened in append mode. The kernel ignores the position argument and always appends the data to the end of the file.
Optional
position: numberThe offset from the beginning of the file where the data from buffer
should be written. If position
is not a number
, the data will be written at the current
position. See the POSIX pwrite(2) documentation for more detail.
Optional
encoding: BufferEncodingAsynchronously writes data to a file, replacing the file if it already exists. The underlying file will not be closed automatically.
The FileHandle
must have been opened for writing.
It is unsafe to call writeFile()
multiple times on the same file without waiting for the Promise
to be resolved (or rejected).
The data to write. If something other than a Buffer
or Uint8Array
is provided, the value is coerced to a string.
Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
encoding
defaults to 'utf8'
.mode
defaults to 0o666
.flag
defaults to 'w'
.
The file descriptor for this file handle.