FileSystem.FileHandle
This module provides access to files through FileHandles. A FileHandle represents an open file. If you know you're going to perform repeated operations on a file, it will be more efficient through a FileHandle.
A file handle is used to perform operations on a file, like reading and writing.
Having a file handle gives you access to perform certain operations, so make sure you only pass a file handle to code you can trust.
The FileHandle type also contains the read and write access permissions as part of its type.
An alias for a FileHandle that can be used in read operations.
An alias for a FileHandle that can be used in write operations.
An alias for a FileHandle that can be used for both read and write operations.
A type that represents the permission to read from a file.
A type that represents the permission to write to a file.
This lets you downgrade a ReadWriteableFileHandle to a FileHandle that only has read permission.
Comes in handy when you want full access to a file in some parts of your code, but limited access in other parts of your code.
This let's you downgrade a ReadWriteableFileHandle to a FileHandle that only has write permission.
Comes in handy when you want full access to a file in some parts of your code, but limited access in other parts of your code.
File open/close
Open the file at the provided path with read permissions.
There are several ways to open a file for writing.
EnsureEmpty
will create an empty file if it doesn't exist, or remove all contents of a file if it does exist.ExpectExisting
will fail the task if it doesn't exist.ExpectNotExisting
will fail the task if the file does exist.
Open a file at the provided path with write permissions.
Open a file for at the provided path with both read and write permissions.
Close a file. All operations performed against the given FileHandle will fail.
File metadata
Retrieve Metadata about the file represented by the FileHandle.
Change how different users can access a file.
Change who owns the file. You'll need the ID of the new user and group who will own the file.
This will let you set the timestamp for when the file was last accessed, and last modified. The times will be rounded down to the closest second.
Read from file
Read all bytes in a file.
Read length
number of bytes from a file, starting at offset
bytes.
Write to file
Write the provided bytes into the file. If the file is not empty, bytes will be overwritten.
Write bytes into a specific location of a file.
Make sure that a file is of the given size. If the file is larger than the given size, excess bytes are discarded. If the file is smaller than the given size, zeroes will be added until it is of the given size.
Usually when you make changes to a file, the changes aren't actually written to disk right away. The changes are likely placed in an OS-level buffer, and flushed to disk when the OS decides its time to do so.
This task, when executed, will force changes to be written to disk.