file Module
The file module handles filesystem operations: reading/writing text, reading/writing binary buffers, line-by-line streaming, querying file metadata, modifying permissions (chmod), and managing symlinks.
Importing
djazair
use file
Convenience Functions
| Function | Description |
|---|---|
file.read(path) | Reads entire file content as a UTF-8 String. |
file.write(path, text) | Overwrites file with text string. |
file.append(path, text) | Appends text to the end of file. |
file.readLines(path) | Reads entire file and returns an Array of lines. |
file.writeLines(path, lines) | Writes an Array of strings to file, separated by newlines. |
file.exists(path) | Returns True if file or directory exists. |
file.isFile(path) | Returns True if path points to a regular file. |
file.isDir(path) | Returns True if path points to a directory. |
file.delete(path) | Deletes the file. |
file.copy(src, dest) | Copies file from src to dest. |
file.move(src, dest) | Moves or renames file from src to dest. |
file.stat(path) | Returns a Map of file metadata: size, modified timestamp, etc. |
file.chmod(path, mode) | Changes file permissions (e.g. 0644). |
file.writeBytes(path, bytes) | Writes raw byte buffer to binary file. |
file.readBytes(path) | Reads raw byte buffer from binary file. |
Low-Level FileHandle Streaming
For fine-grained control or streaming large files, open files using file.open(path, mode):
djazair
use file
# Open file for writing
let handle = file.open("log.txt", "w")
handle.write("Line 1: system started
")
handle.write("Line 2: connected to database
")
handle.flush()
handle.close()
# Open file for reading
let reader = file.open("log.txt", "r")
let firstLine = reader.readLine()
print("First line: ${firstLine}")
reader.close()