file
File input and output operations
Import
_ <- fat.file
Type contributions
Name | Signature | Brief |
---|---|---|
FileInfo | (modTime: Epoch, size: Text) | File metadata |
Methods
Name | Signature | Brief |
---|---|---|
basePath | (): Text | Extract path where app was called |
exists | (path: Text): Boolean | Check file exists on provided path |
read | (path: Text): Text | Read file from path (text mode) |
readBin | (path: Text): Chunk | Read file from path (binary mode) |
write | (path: Text, src): Boolean | Write src to file and return success |
append | (path: Text, src): Boolean | Append to file and return success |
remove | (path: Text): Boolean | Remove files and directories |
isDir | (path: Text): Boolean | Check if path is a directory |
mkDir | (path: Text, safe: Boolean) | Create a directory |
lsDir | (path: Text): List | Get list of files in a directory |
stat | (path: Text): FileInfo | Get file metadata |
Usage Notes
read
On exception:
- logs error to
stderr
- returns
null
read
cannot see builtin "files", butreadLib
from SDK lib can
write/append
These methods will intelligently handle different data types to optimize file output. For the Chunk
type, they automatically write in binary mode, and for the Text
type, as plain text. For other types, they implicitly stringify the src
value before writing, ensuring all values are handled gracefully.
Exceptions:
- logs error to
stderr
- returns
false
remove
The behavior is similar to rm -r
, removing files and directories recursively.
starting with version
3.0.1
, symbolic links are not followed; in version3.0.0
, symbolic links were followed; previous versions offry
did not implement recursive deletion
mkDir
The behavior is similar to mkdir -p
, creating intermediate directories when necessary.
If safe
is set to true
, the directory gets 0700 permission instead of default 0755, which is less protected.