Comment on page
file
The File library allows reading and writing from/to external files using a C-like File IO API.
These functions are considered dangerous and require the user to manually permit them
A handle representing a file that has been opened
using Handle = s32;
The mode to open a file in. Read opens the file in read-only mode Write opens the file in read and write mode Create creates a new file if it doesn't exist and overwrites an existing file
enum Mode : u8 {
Create,
Read,
Write
};
Opens a file
path
: The path to the file to openmode
: File open modereturn
: Handle to the newly opened file
fn open(str path, std::file::Mode mode);
Closes a file handle that has been opened previously
handle
: The handle to close
fn close(std::file::Handle handle);
Reads the content of a file into a string
handle
: The file handle to read fromsize
: Number of bytes to readreturn
: String containing the read data
fn read(std::file::Handle handle, u64 size);
Writes the content of a string into a file
handle
: The file handle to write todata
: String or Pattern to write to the file
fn write(std::file::Handle handle, auto data);
Sets the current cursor position in the given file handle
handle
: The file handle to set the cursor position inoffset
: The offset to move the cursor to
fn seek(std::file::Handle handle, u64 offset);
Queries the size of a file
handle
: The handle of the file to get the size ofreturn
: The file's size
fn size(std::file::Handle handle);
Resizes a file
handle
: The handle of the file to resize
fn resize(std::file::Handle handle, u64 size);
Flushes changes made to a file to disk
handle
: The handle of the file to flush
fn flush(std::file::Handle handle);
Deletes a file from disk. This will also automatically close this file
handle
: The handle of the file to delete
fn remove(std::file::Handle handle);
Last modified 7mo ago