file
Documentation for 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
Types
std::file::Handle
A handle representing a file that has been opened
using Handle = ;std::file::Mode
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 : {
Create,
Read,
Write
};Functions
std::file::open
Opens a file
path: The path to the file to openmode: File open modereturn: Handle to the newly opened file
fn open( path, std::file::Mode mode);std::file::close
Closes a file handle that has been opened previously
handle: The handle to close
fn close(std::file::Handle handle);std::file::read
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, size);std::file::write
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, data);std::file::seek
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, offset);std::file::size
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);std::file::resize
Resizes a file
handle: The handle of the file to resize
fn resize(std::file::Handle handle, size);std::file::flush
Flushes changes made to a file to disk
handle: The handle of the file to flush
fn flush(std::file::Handle handle);std::file::remove
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);std::file::create_directories
Create all directories for the provided path
path: The path for which all directories should be created
fn create_directories( path);