Filesystem
Documentation of the filesystem library.
The filesystem
library allows for interacting with filesystem
components more easily and properly processing paths.
filesystem.absolutePath(path: string): string, string
Returns the address of the filesystem component thatpath
leads to and the absolute path in said filesystem component.filesystem.canonical(path: string): string
Returns the canonical path ofpath
(one containing no special segments like . or ..). For example, the canonical path of/home/../halyde/./apps
is/halyde/apps
.filesystem.concat(path1: string, path2: string): string
Returns the result of concatenating thepath1
andpath2
together.filesystem.copy(fromPath: string, toPath: string): boolean or nil, string
Copies the file atfromPath
totoPath
.toPath
must contain the file's name. Returnsnil
and an error message if an error occurred.filesystem.exists(path: string): boolean
Returns whether there is an object atpath
or not.filesystem.isDirectory(path: string): boolean
Returns whether the object atpath
is a directory or not.filesystem.list(path: string): table or nil, string
Returns a table of all objects atpath
, if it is a directory. Directories are suffixed with/
. Returnsnil
and an error message if an error occurred.filesystem.makeDirectory(path: string): boolean or nil, string
Creates a directory atpath
. Returnsnil
and an error message if an error occurred.filesystem.open(path: string, [mode: string]): table or nil, string
Opens a file atpath
for reading/writing.mode
defaults tor
. Possible modes arer
,rb
,w
,wb
,a
andab
. Returns a file stream - a table with 3 functions. Returnsnil
and an error message if an error occurred.stream:read(amount: number): string or nil, string
Tries to read the specified number of bytes from the file stream. Returnsnil
and an error message if an error occurred.stream:write(data: string): boolean or nil, string
Writesdata
to the file stream. Returnsnil
and an error message if an error occurred.stream:readBytes(n: number): number or nil
Returns the unsigned integer of a specific number of bytes, in big endian. Ifn
is 1, then it will return one byte from the file as a number.stream:readUnicodeChar(): string
Reads an Unicode character, and returns it.stream:iterateBytes(): function
Returns an iterator function that returns a byte (number
) when called. When the stream ends, it will automatically get closed.stream:iterateUnicodeChars(): function
Returns an iterator function that returns an Unicode character (string
) when called. When the stream ends, it will automatically get closed.stream:close()
Closes the file stream.
filesystem.makeReadStream(content: string): table
Makes a new readable file stream with the specified content and returns it. (seefilesystem.open()
)filesystem.remove(path: string): boolean or nil, string
Removes the object atpath
. Returnsnil
and an error message if an error occurred.filesystem.rename(path: string): boolean or nil, string
Renames the object at the specified path. Returnsnil
and an error message if an error occurred.filesystem.size(path: string): number
Returns the size of the file atpath
. Returns 0 if the file does not exist or if it is a directory.
Last updated