FileHandle 类
而是,始终显式关闭 FileHandle
。
Node.js 将来可能会更改此行为。
A FileHandle
object is a wrapper for a numeric file descriptor.
Instances of FileHandle
are distinct from numeric file descriptors
in that they provide an object oriented API for working with files.
If a FileHandle
is not closed using the
filehandle.close()
method, it might automatically close the file descriptor
and will emit a process warning, thereby helping to prevent memory leaks.
Please do not rely on this behavior because it is unreliable and
the file may not be closed. Instead, always explicitly close FileHandle
s.
Node.js may change this behavior in the future.
Instances of the FileHandle
object are created internally by the
fsPromises.open()
method.
Unlike the callback-based API (fs.fstat()
, fs.fchown()
, fs.fchmod()
, and
so on), a numeric file descriptor is not used by the promise-based API. Instead,
the promise-based API uses the FileHandle
class in order to help avoid
accidental leaking of unclosed file descriptors after a Promise
is resolved or
rejected.