Opens or creates the file at filePath with mode specifying how
it should be opened. For example "wb" to open the file for writing
in binary mode. This is the same format as fopen() from the C
standard library.
Path to file to open or create.
Mode to use.
StaticSEEK_Passed to seek() to specify that the offset is relative to the current
file position.
StaticSEEK_Passed to seek() to specify that the offset is relative to the end of
the file.
StaticSEEK_Passed to seek() to specify that the offset is relative to the start
of the file.
Closes the file. You should call this function when you’re done with the file unless you are fine with this happening when the object is garbage-collected or the script is unloaded.
Flushes any buffered data to the underlying file.
StaticreadOpens the binary file at filePath, reads all of its content into an
ArrayBuffer, and then closes the file.
The file to read from.
StaticreadOpens the UTF-8 encoded text file at filePath, reads all of its text
into a string, and then closes the file.
The file to read from.
Reads up to n bytes from the file, or the rest of the file if
unspecified. Returns an empty buffer when the end of the file is
reached.
Optionaln: numberThe maximum number of bytes to read.
Reads one line of text from the file, with the newline included. Returns an empty string when the end of the file is reached.
Ensures that the data is valid UTF-8 and throws an error otherwise.
Reads up to n bytes from the file into a string. If n is omitted,
the rest of the file is read. Returns an empty string when the end of the
file is reached.
Ensures that the data is valid UTF-8 and throws an error otherwise.
Optionaln: numberThe maximum number of bytes to read.
Changes the current file position to the specified offset, in bytes.
Returns the resulting offset.
The byte offset to seek to.
Optionalwhence: numberWhat the offset is relative to (default: File.SEEK_SET).
Returns the current file position, in bytes.
Synchronously writes data to the file.
Data to write.
StaticwriteCreates a new file at filePath, writes the specified bytes to it, and
then closes the file. The target file is overwritten in case it already
exists.
The file to write to.
The bytes to write to the file.
StaticwriteCreates a new file at filePath, writes the specified text to it
encoded as UTF-8, and then closes the file. The target file is
overwritten in case it already exists.
The file to write to.
The string to write to the file.
Provides basic filesystem access.