FileHandle

@native @JSType trait FileHandle extends StObject with _TransferListItem
trait StObject
class Object
trait Any
class Object
trait Matchable
class Any

Value members

Concrete methods

def appendFile(data: String): Promise[Unit]

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.

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.

Value Params
data

The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.

options

Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag. If encoding is not supplied, the default of 'utf8' is used. If mode is not supplied, the default of 0o666 is used. If mode is a string, it is parsed as an octal integer. If flag is not supplied, the default of 'a' is used.

def appendFile(data: String, options: BaseEncodingOptionsmodeMoEncoding): Promise[Unit]
def appendFile(data: String, options: BufferEncoding): Promise[Unit]
def appendFile(data: Uint8Array): Promise[Unit]
def appendFile(data: Uint8Array, options: BaseEncodingOptionsmodeMoEncoding): Promise[Unit]
def appendFile(data: Uint8Array, options: BufferEncoding): Promise[Unit]
def chmod(mode: Mode): Promise[Unit]

Asynchronous fchmod(2) - Change permissions of a file.

Asynchronous fchmod(2) - Change permissions of a file.

Value Params
mode

A file mode. If a string is passed, it is parsed as an octal integer.

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

Asynchronous fchown(2) - Change ownership of a file.

Asynchronous fchown(2) - Change ownership of a file.

def close(): Promise[Unit]

Asynchronous close(2) - close a FileHandle.

Asynchronous close(2) - close a FileHandle.

def datasync(): Promise[Unit]

Asynchronous fdatasync(2) - synchronize a file's in-core state with storage device.

Asynchronous fdatasync(2) - synchronize a file's in-core state with storage device.

def read[TBuffer](buffer: TBuffer): Promise[Buffer[TBuffer]]

Asynchronously reads data from the file. The FileHandle must have been opened for reading.

Asynchronously reads data from the file. The FileHandle must have been opened for reading.

Value Params
buffer

The buffer that the data will be written to.

length

The number of bytes to read.

offset

The offset in the buffer at which to start writing.

position

The offset from the beginning of the file from which data should be read. If null, data will be read from the current position.

def read[TBuffer](buffer: TBuffer, offset: Double): Promise[Buffer[TBuffer]]
def read[TBuffer](buffer: TBuffer, offset: Double, length: Double): Promise[Buffer[TBuffer]]
def read[TBuffer](buffer: TBuffer, offset: Double, length: Double, position: Double): Promise[Buffer[TBuffer]]
def read[TBuffer](buffer: TBuffer, offset: Double, length: Null, position: Double): Promise[Buffer[TBuffer]]
def read[TBuffer](buffer: TBuffer, offset: Double, length: Unit, position: Double): Promise[Buffer[TBuffer]]
def read[TBuffer](buffer: TBuffer, offset: Null, length: Double): Promise[Buffer[TBuffer]]
def read[TBuffer](buffer: TBuffer, offset: Null, length: Double, position: Double): Promise[Buffer[TBuffer]]
def read[TBuffer](buffer: TBuffer, offset: Null, length: Null, position: Double): Promise[Buffer[TBuffer]]
def read[TBuffer](buffer: TBuffer, offset: Null, length: Unit, position: Double): Promise[Buffer[TBuffer]]
def read[TBuffer](buffer: TBuffer, offset: Unit, length: Double): Promise[Buffer[TBuffer]]
def read[TBuffer](buffer: TBuffer, offset: Unit, length: Double, position: Double): Promise[Buffer[TBuffer]]
def read[TBuffer](buffer: TBuffer, offset: Unit, length: Null, position: Double): Promise[Buffer[TBuffer]]
def read[TBuffer](buffer: TBuffer, offset: Unit, length: Unit, position: Double): Promise[Buffer[TBuffer]]
def readFile(): Promise[Buffer]

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

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

Value Params
options

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

def readFile(options: BaseEncodingOptionsflagOp): Promise[String | Buffer]
def readFile(options: EncodingBufferEncoding): Promise[String]

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

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

Value Params
options

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

def readFile(options: 3): Promise[Buffer]
def readFile(options: BufferEncoding): Promise[String]
def readv(buffers: Array[ArrayBufferView]): Promise[ReadVResult]

See fs.readv promisified version.

See fs.readv promisified version.

def readv(buffers: Array[ArrayBufferView], position: Double): Promise[ReadVResult]
def stat(): Promise[Stats]

Asynchronous fstat(2) - Get file status.

Asynchronous fstat(2) - Get file status.

def stat(opts: StatOptionsbigintfalseund): Promise[Stats]
def stat(opts: StatOptionsbiginttrue): Promise[BigIntStats]
def stat(opts: StatOptions): Promise[Stats | BigIntStats]
def sync(): Promise[Unit]

Asynchronous fsync(2) - synchronize a file's in-core state with the underlying storage device.

Asynchronous fsync(2) - synchronize a file's in-core state with the underlying storage device.

def truncate(): Promise[Unit]

Asynchronous ftruncate(2) - Truncate a file to a specified length.

Asynchronous ftruncate(2) - Truncate a file to a specified length.

Value Params
len

If not specified, defaults to 0.

def truncate(len: Double): Promise[Unit]
def utimes(atime: String, mtime: String): Promise[Unit]

Asynchronously change file timestamps of the file.

Asynchronously change file timestamps of the file.

Value Params
atime

The last access time. If a string is provided, it will be coerced to number.

mtime

The last modified time. If a string is provided, it will be coerced to number.

def utimes(atime: String, mtime: Date): Promise[Unit]
def utimes(atime: String, mtime: Double): Promise[Unit]
def utimes(atime: Date, mtime: String): Promise[Unit]
def utimes(atime: Date, mtime: Date): Promise[Unit]
def utimes(atime: Date, mtime: Double): Promise[Unit]
def utimes(atime: Double, mtime: String): Promise[Unit]
def utimes(atime: Double, mtime: Date): Promise[Unit]
def utimes(atime: Double, mtime: Double): Promise[Unit]
def write(data: String): Promise[BufferBytesWritten]

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.

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.

Value Params
encoding

The expected string encoding.

position

The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.

string

A string to write.

def write(data: String, position: Double): Promise[BufferBytesWritten]
def write(data: String, position: Double, encoding: BufferEncoding): Promise[BufferBytesWritten]
def write(data: String, position: Null, encoding: BufferEncoding): Promise[BufferBytesWritten]
def write(data: String, position: Unit, encoding: BufferEncoding): Promise[BufferBytesWritten]
def write(data: Uint8Array): Promise[BufferBytesWritten]
def write(data: Uint8Array, position: Double): Promise[BufferBytesWritten]
def write(data: Uint8Array, position: Double, encoding: BufferEncoding): Promise[BufferBytesWritten]
def write(data: Uint8Array, position: Null, encoding: BufferEncoding): Promise[BufferBytesWritten]
def write(data: Uint8Array, position: Unit, encoding: BufferEncoding): Promise[BufferBytesWritten]
def write[TBuffer](buffer: TBuffer): Promise[BytesWritten[TBuffer]]

Asynchronously writes buffer to the file. The FileHandle must have been opened for writing.

Asynchronously writes buffer to the file. The FileHandle must have been opened for writing.

Value Params
buffer

The buffer that the data will be written to.

length

The number of bytes to write. If not supplied, defaults to buffer.length - offset.

offset

The part of the buffer to be written. If not supplied, defaults to 0.

position

The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.

def write[TBuffer](buffer: TBuffer, offset: Double): Promise[BytesWritten[TBuffer]]
def write[TBuffer](buffer: TBuffer, offset: Double, length: Double): Promise[BytesWritten[TBuffer]]
def write[TBuffer](buffer: TBuffer, offset: Double, length: Double, position: Double): Promise[BytesWritten[TBuffer]]
def write[TBuffer](buffer: TBuffer, offset: Double, length: Null, position: Double): Promise[BytesWritten[TBuffer]]
def write[TBuffer](buffer: TBuffer, offset: Double, length: Unit, position: Double): Promise[BytesWritten[TBuffer]]
def write[TBuffer](buffer: TBuffer, offset: Null, length: Double): Promise[BytesWritten[TBuffer]]
def write[TBuffer](buffer: TBuffer, offset: Null, length: Double, position: Double): Promise[BytesWritten[TBuffer]]
def write[TBuffer](buffer: TBuffer, offset: Null, length: Null, position: Double): Promise[BytesWritten[TBuffer]]
def write[TBuffer](buffer: TBuffer, offset: Null, length: Unit, position: Double): Promise[BytesWritten[TBuffer]]
def write[TBuffer](buffer: TBuffer, offset: Unit, length: Double): Promise[BytesWritten[TBuffer]]
def write[TBuffer](buffer: TBuffer, offset: Unit, length: Double, position: Double): Promise[BytesWritten[TBuffer]]
def write[TBuffer](buffer: TBuffer, offset: Unit, length: Null, position: Double): Promise[BytesWritten[TBuffer]]
def write[TBuffer](buffer: TBuffer, offset: Unit, length: Unit, position: Double): Promise[BytesWritten[TBuffer]]
def writeFile(data: String): Promise[Unit]

Asynchronously 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).

Asynchronously 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).

Value Params
data

The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.

options

Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag. If encoding is not supplied, the default of 'utf8' is used. If mode is not supplied, the default of 0o666 is used. If mode is a string, it is parsed as an octal integer. If flag is not supplied, the default of 'w' is used.

def writeFile(data: String, options: BaseEncodingOptionsmodeMo): Promise[Unit]
def writeFile(data: String, options: BufferEncoding): Promise[Unit]
def writeFile(data: Uint8Array): Promise[Unit]
def writeFile(data: Uint8Array, options: BaseEncodingOptionsmodeMo): Promise[Unit]
def writeFile(data: Uint8Array, options: BufferEncoding): Promise[Unit]
def writev(buffers: Array[ArrayBufferView]): Promise[WriteVResult]

See fs.writev promisified version.

See fs.writev promisified version.

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

Inherited methods

def hasOwnProperty(v: String): Boolean
Inherited from
Object
def isPrototypeOf(v: Object): Boolean
Inherited from
Object
def propertyIsEnumerable(v: String): Boolean
Inherited from
Object
def toLocaleString(): String
Inherited from
Object
def valueOf(): Any
Inherited from
Object

Concrete fields

val fd: Double

Gets the file descriptor for this file handle.

Gets the file descriptor for this file handle.