Packages

trait FileHandle extends Object with StObject with _TransferListItem

Annotations
@JSType() @native()
Linear Supertypes
_TransferListItem, StObject, Object, Any, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. FileHandle
  2. _TransferListItem
  3. StObject
  4. Object
  5. Any
  6. AnyRef
  7. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def appendFile(data: Uint8Array, options: BufferEncoding): Promise[Unit]
  5. def appendFile(data: Uint8Array, options: ObjectEncodingOptions with FlagAndOpenMode): Promise[Unit]
  6. def appendFile(data: Uint8Array): Promise[Unit]
  7. def appendFile(data: String, options: BufferEncoding): Promise[Unit]
  8. def appendFile(data: String, options: ObjectEncodingOptions with FlagAndOpenMode): Promise[Unit]
  9. def appendFile(data: String): Promise[Unit]

    Alias of filehandle.writeFile().

    Alias of filehandle.writeFile().

    When operating on file handles, the mode cannot be changed from what it was set to with fsPromises.open(). Therefore, this is equivalent to filehandle.writeFile().

    returns

    Fulfills with undefined upon success.

    Since

    v10.0.0

  10. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  11. def chmod(mode: Mode): Promise[Unit]

    Modifies the permissions on the file.

    Modifies the permissions on the file. See [chmod(2)](http://man7.org/linux/man-pages/man2/chmod.2.html).

    mode

    the file mode bit mask.

    returns

    Fulfills with undefined upon success.

    Since

    v10.0.0

  12. def chown(uid: Double, gid: Double): Promise[Unit]

    Changes the ownership of the file.

    Changes the ownership of the file. A wrapper for [chown(2)](http://man7.org/linux/man-pages/man2/chown.2.html).

    uid

    The file's new owner's user id.

    gid

    The file's new group's group id.

    returns

    Fulfills with undefined upon success.

    Since

    v10.0.0

  13. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
  14. def close(): Promise[Unit]

    Closes the file handle after waiting for any pending operation on the handle to complete.

    Closes the file handle after waiting for any pending operation on the handle to complete.

    js import { open } from 'fs/promises';

    let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }

    returns

    Fulfills with undefined upon success.

    Since

    v10.0.0

  15. def createReadStream(options: CreateReadStreamOptions): ReadStream
  16. def createReadStream(): ReadStream

    Unlike the 16 kb default highWaterMark for a stream.Readable, the stream returned by this method has a default highWaterMark of 64 kb.

    Unlike the 16 kb default highWaterMark for a stream.Readable, the stream returned by this method has a default highWaterMark of 64 kb.

    options can include start and end values to read a range of bytes from the file instead of the entire file. Both start and end are inclusive and start counting at 0, allowed values are in the \[0, [Number.MAX_SAFE_INTEGER](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)\] range. If start is omitted or undefined, filehandle.createReadStream() reads sequentially from the current file position. The encoding can be any one of those accepted by Buffer.

    If the FileHandle points to a character device that only supports blocking reads (such as keyboard or sound card), read operations do not finish until data is available. This can prevent the process from exiting and the stream from closing naturally.

    By default, the stream will emit a 'close' event after it has been destroyed. Set the emitClose option to false to change this behavior.

    js import { open } from 'fs/promises';

    const fd = await open('/dev/input/event0'); // Create a stream from some character device. const stream = fd.createReadStream(); setTimeout(() => { stream.close(); // This may not close the stream. // Artificially marking end-of-stream, as if the underlying resource had // indicated end-of-file by itself, allows the stream to close. // This does not cancel pending read operations, and if there is such an // operation, the process may still not be able to exit successfully // until it finishes. stream.push(null); stream.read(0); }, 100);

    If autoClose is false, then the file descriptor won't be closed, even if there's an error. It is the application's responsibility to close it and make sure there's no file descriptor leak. If autoClose is set to true (default behavior), on 'error' or 'end' the file descriptor will be closed automatically.

    An example to read the last 10 bytes of a file which is 100 bytes long:

    js import { open } from 'fs/promises';

    const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });

    Since

    v16.11.0

  17. def createWriteStream(options: CreateWriteStreamOptions): WriteStream
  18. def createWriteStream(): WriteStream

    options may also include a start option to allow writing data at some position past the beginning of the file, allowed values are in the \[0, [Number.MAX_SAFE_INTEGER](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)\] range.

    options may also include a start option to allow writing data at some position past the beginning of the file, allowed values are in the \[0, [Number.MAX_SAFE_INTEGER](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)\] range. Modifying a file rather than replacing it may require the flags open option to be set to r+ rather than the default r. The encoding can be any one of those accepted by Buffer.

    If autoClose is set to true (default behavior) on 'error' or 'finish'the file descriptor will be closed automatically. If autoClose is false, then the file descriptor won't be closed, even if there's an error. It is the application's responsibility to close it and make sure there's no file descriptor leak.

    By default, the stream will emit a 'close' event after it has been destroyed. Set the emitClose option to false to change this behavior.

    Since

    v16.11.0

  19. def datasync(): Promise[Unit]

    Forces all currently queued I/O operations associated with the file to the operating system's synchronized I/O completion state.

    Forces all currently queued I/O operations associated with the file to the operating system's synchronized I/O completion state. Refer to the POSIX [fdatasync(2)](http://man7.org/linux/man-pages/man2/fdatasync.2.html) documentation for details.

    Unlike filehandle.sync this method does not flush modified metadata.

    returns

    Fulfills with undefined upon success.

    Since

    v10.0.0

  20. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  21. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  22. val fd: Double

    The numeric file descriptor managed by the {FileHandle} object.

    The numeric file descriptor managed by the {FileHandle} object.

    Since

    v10.0.0

  23. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  24. def hasOwnProperty(v: String): Boolean
    Definition Classes
    Object
  25. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  26. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  27. def isPrototypeOf(v: Object): Boolean
    Definition Classes
    Object
  28. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  29. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  30. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  31. def propertyIsEnumerable(v: String): Boolean
    Definition Classes
    Object
  32. def read[T](options: FileReadOptions[T]): Promise[FileReadResult[T]]
  33. def read[T](buffer: T, offset: Unit, length: Unit, position: Double): Promise[FileReadResult[T]]
  34. def read[T](buffer: T, offset: Unit, length: Null, position: Double): Promise[FileReadResult[T]]
  35. def read[T](buffer: T, offset: Unit, length: Double, position: Double): Promise[FileReadResult[T]]
  36. def read[T](buffer: T, offset: Unit, length: Double): Promise[FileReadResult[T]]
  37. def read[T](buffer: T, offset: Null, length: Unit, position: Double): Promise[FileReadResult[T]]
  38. def read[T](buffer: T, offset: Null, length: Null, position: Double): Promise[FileReadResult[T]]
  39. def read[T](buffer: T, offset: Null, length: Double, position: Double): Promise[FileReadResult[T]]
  40. def read[T](buffer: T, offset: Null, length: Double): Promise[FileReadResult[T]]
  41. def read[T](buffer: T, offset: Double, length: Unit, position: Double): Promise[FileReadResult[T]]
  42. def read[T](buffer: T, offset: Double, length: Null, position: Double): Promise[FileReadResult[T]]
  43. def read[T](buffer: T, offset: Double, length: Double, position: Double): Promise[FileReadResult[T]]
  44. def read[T](buffer: T, offset: Double, length: Double): Promise[FileReadResult[T]]
  45. def read[T](buffer: T, offset: Double): Promise[FileReadResult[T]]
  46. def read[T](buffer: T): Promise[FileReadResult[T]]

    Reads data from the file and stores that in the given buffer.

    Reads data from the file and stores that in the given buffer.

    If the file is not modified concurrently, the end-of-file is reached when the number of bytes read is zero.

    buffer

    A buffer that will be filled with the file data read.

    returns

    Fulfills upon success with an object with two properties:

    Since

    v10.0.0

  47. def read[T](): Promise[FileReadResult[T]]
  48. def readFile(options: BufferEncoding): Promise[String]
  49. def readFile(options: 3): Promise[Buffer]
  50. def readFile(options: ObjectEncodingOptionsflagFlag): Promise[|[String, Buffer]]
  51. def readFile(options: EncodingBufferEncoding): Promise[String]

    Asynchronously reads the entire contents of a file.

    Asynchronously reads the entire contents of a file. The underlying file will _not_ be closed automatically. The FileHandle must have been opened for reading.

    options

    An object that may contain an optional flag. If a flag is not provided, it defaults to 'r'.

  52. def readFile(): Promise[Buffer]

    Asynchronously reads the entire contents of a file.

    Asynchronously reads the entire contents of a file. The underlying file will _not_ be closed automatically. The FileHandle must have been opened for reading.

  53. def readv(buffers: Array[ArrayBufferView], position: Double): Promise[ReadVResult]
  54. def readv(buffers: Array[ArrayBufferView]): Promise[ReadVResult]

    Read from a file and write to an array of [ArrayBufferView](https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView) s

    Read from a file and write to an array of [ArrayBufferView](https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView) s

    returns

    Fulfills upon success an object containing two properties:

    Since

    v13.13.0, v12.17.0

  55. def stat(opts: StatOptions): Promise[|[Stats, BigIntStats]]
  56. def stat(opts: StatOptionsbiginttrue): Promise[BigIntStats]
  57. def stat(opts: StatOptionsbigintfalseund): Promise[Stats]
  58. def stat(): Promise[Stats]

    returns

    Fulfills with an {fs.Stats} for the file.

    Since

    v10.0.0

  59. def sync(): Promise[Unit]

    Request that all data for the open file descriptor is flushed to the storage device.

    Request that all data for the open file descriptor is flushed to the storage device. The specific implementation is operating system and device specific. Refer to the POSIX [fsync(2)](http://man7.org/linux/man-pages/man2/fsync.2.html) documentation for more detail.

    returns

    Fufills with undefined upon success.

    Since

    v10.0.0

  60. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  61. def toLocaleString(): String
    Definition Classes
    Object
  62. def toString(): String
    Definition Classes
    AnyRef → Any
  63. def truncate(len: Double): Promise[Unit]
  64. def truncate(): Promise[Unit]

    Truncates the file.

    Truncates the file.

    If the file was larger than len bytes, only the first len bytes will be retained in the file.

    The following example retains only the first four bytes of the file:

    js import { open } from 'fs/promises';

    let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }

    If the file previously was shorter than len bytes, it is extended, and the extended part is filled with null bytes ('\0'):

    If len is negative then 0 will be used.

    returns

    Fulfills with undefined upon success.

    Since

    v10.0.0

  65. def utimes(atime: Double, mtime: Double): Promise[Unit]
  66. def utimes(atime: Double, mtime: Date): Promise[Unit]
  67. def utimes(atime: Double, mtime: String): Promise[Unit]
  68. def utimes(atime: Date, mtime: Double): Promise[Unit]
  69. def utimes(atime: Date, mtime: Date): Promise[Unit]
  70. def utimes(atime: Date, mtime: String): Promise[Unit]
  71. def utimes(atime: String, mtime: Double): Promise[Unit]
  72. def utimes(atime: String, mtime: Date): Promise[Unit]
  73. def utimes(atime: String, mtime: String): Promise[Unit]

    Change the file system timestamps of the object referenced by the FileHandle then resolves the promise with no arguments upon success.

    Change the file system timestamps of the object referenced by the FileHandle then resolves the promise with no arguments upon success.

    Since

    v10.0.0

  74. def valueOf(): Any
    Definition Classes
    Object
  75. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  76. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  77. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  78. def write[TBuffer](buffer: TBuffer, offset: Unit, length: Unit, position: Double): Promise[Buffer[TBuffer]]
  79. def write[TBuffer](buffer: TBuffer, offset: Unit, length: Null, position: Double): Promise[Buffer[TBuffer]]
  80. def write[TBuffer](buffer: TBuffer, offset: Unit, length: Double, position: Double): Promise[Buffer[TBuffer]]
  81. def write[TBuffer](buffer: TBuffer, offset: Unit, length: Double): Promise[Buffer[TBuffer]]
  82. def write[TBuffer](buffer: TBuffer, offset: Null, length: Unit, position: Double): Promise[Buffer[TBuffer]]
  83. def write[TBuffer](buffer: TBuffer, offset: Null, length: Null, position: Double): Promise[Buffer[TBuffer]]
  84. def write[TBuffer](buffer: TBuffer, offset: Null, length: Double, position: Double): Promise[Buffer[TBuffer]]
  85. def write[TBuffer](buffer: TBuffer, offset: Null, length: Double): Promise[Buffer[TBuffer]]
  86. def write[TBuffer](buffer: TBuffer, offset: Double, length: Unit, position: Double): Promise[Buffer[TBuffer]]
  87. def write[TBuffer](buffer: TBuffer, offset: Double, length: Null, position: Double): Promise[Buffer[TBuffer]]
  88. def write[TBuffer](buffer: TBuffer, offset: Double, length: Double, position: Double): Promise[Buffer[TBuffer]]
  89. def write[TBuffer](buffer: TBuffer, offset: Double, length: Double): Promise[Buffer[TBuffer]]
  90. def write[TBuffer](buffer: TBuffer, offset: Double): Promise[Buffer[TBuffer]]
  91. def write[TBuffer](buffer: TBuffer): Promise[Buffer[TBuffer]]

    Write buffer to the file.

    Write buffer to the file.

    If buffer is a plain object, it must have an own (not inherited) toStringfunction property.

    The promise is resolved 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 resolved (or rejected). For this scenario, use fs.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.

    Since

    v10.0.0

  92. def write(data: String, position: Unit, encoding: BufferEncoding): Promise[BytesWritten]
  93. def write(data: String, position: Null, encoding: BufferEncoding): Promise[BytesWritten]
  94. def write(data: String, position: Double, encoding: BufferEncoding): Promise[BytesWritten]
  95. def write(data: String, position: Double): Promise[BytesWritten]
  96. def write(data: String): Promise[BytesWritten]
  97. def writeFile(data: Uint8Array, options: BufferEncoding): Promise[Unit]
  98. def writeFile(data: Uint8Array, options: ObjectEncodingOptions with FlagAndOpenMode with Abortable): Promise[Unit]
  99. def writeFile(data: Uint8Array): Promise[Unit]
  100. def writeFile(data: String, options: BufferEncoding): Promise[Unit]
  101. def writeFile(data: String, options: ObjectEncodingOptions with FlagAndOpenMode with Abortable): Promise[Unit]
  102. def writeFile(data: String): Promise[Unit]

    Asynchronously writes data to a file, replacing the file if it already exists.data can be a string, a buffer, an [AsyncIterable](https://tc39.github.io/ecma262/#sec-asynciterable-interface) or [Iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol) object, or an object with an own toString function property.

    Asynchronously writes data to a file, replacing the file if it already exists.data can be a string, a buffer, an [AsyncIterable](https://tc39.github.io/ecma262/#sec-asynciterable-interface) or [Iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol) object, or an object with an own toString function property. The promise is resolved with no arguments upon success.

    If options is a string, then it specifies the encoding.

    The FileHandle has to support writing.

    It is unsafe to use filehandle.writeFile() multiple times on the same file without waiting for the promise to be resolved (or rejected).

    If one or more filehandle.write() calls are made on a file handle and then afilehandle.writeFile() call is made, the data will be written from the current position till the end of the file. It doesn't always write from the beginning of the file.

    Since

    v10.0.0

  103. def writev(buffers: Array[ArrayBufferView], position: Double): Promise[WriteVResult]
  104. def writev(buffers: Array[ArrayBufferView]): Promise[WriteVResult]

    Write an array of [ArrayBufferView](https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView) s to the file.

    Write an array of [ArrayBufferView](https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView) s to the file.

    The promise is resolved with an object containing a two properties:

    It is unsafe to call writev() multiple times on the same file without waiting for the promise to be resolved (or rejected).

    On Linux, positional writes don't 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.

    Since

    v12.9.0

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated
    Deprecated

Inherited from _TransferListItem

Inherited from StObject

Inherited from Object

Inherited from Any

Inherited from AnyRef

Inherited from Any

Ungrouped