Std\File
File – filesystem operations with async I/O support.
Provides file reading, writing, directory listing, and low-level
file handle operations. Async functions (readFile, readFileBytes,
readBytes, writeBytes) use io_uring on Linux for non-blocking I/O.
Functions
Section titled “Functions”readFile : String -> String
Section titled “readFile : String -> String”Read the entire contents of a file as a string. Async (io_uring).
import readFile from Std\File inlet contents = readFile "data.txt" inprintln contentswriteFile : String -> String -> Bool
Section titled “writeFile : String -> String -> Bool”Write a string to a file, creating or overwriting it. Async (io_uring).
Returns true on success.
import writeFile from Std\File inwriteFile "out.txt" "hello world" # => trueappendFile : String -> String -> Bool
Section titled “appendFile : String -> String -> Bool”Append a string to a file. Returns true on success.
import appendFile from Std\File inappendFile "log.txt" "new line\n" # => trueexists : String -> Bool
Section titled “exists : String -> Bool”Check whether a file or directory exists at the given path.
import exists from Std\File inexists "/tmp" # => trueremove : String -> Bool
Section titled “remove : String -> Bool”Delete a file. Returns true on success.
import remove from Std\File inremove "temp.txt" # => truesize : String -> Int
Section titled “size : String -> Int”Returns the size of a file in bytes.
import size from Std\File insize "data.bin" # => 4096listDir : String -> [String]
Section titled “listDir : String -> [String]”List directory contents. Returns a sequence of filenames.
import listDir from Std\File inlistDir "/tmp" # => ["file1.txt", "file2.txt", ...]readLines : String -> Iterator String
Section titled “readLines : String -> Iterator String”Returns an Iterator String that yields lines from the file lazily.
Uses O(1) memory per element.
import readLines from Std\File inlet iter = readLines "big.csv" in# consume with iterator protocolreadFileBytes : String -> ByteArray
Section titled “readFileBytes : String -> ByteArray”Read the entire file as a byte buffer. Async (io_uring).
import readFileBytes from Std\File inlet buf = readFileBytes "image.png" inBytes::length bufwriteFileBytes : String -> ByteArray -> Bool
Section titled “writeFileBytes : String -> ByteArray -> Bool”Write a byte buffer to a file. Returns true on success.
import writeFileBytes from Std\File inimport fromSeq from Std\ByteArray inwriteFileBytes "out.bin" (fromSeq [0, 1, 2, 3])openFile : String -> FileMode -> Linear FileHandle
Section titled “openFile : String -> FileMode -> Linear FileHandle”Open a file with the given mode string ("r", "w", "rw", etc.).
It returns an owning Linear FileHandle, not a raw descriptor. Match the
wrapper once to access the opaque handle and close it:
import openFile, closeFileHandle from Std\File incase openFile "data.txt" Read of Linear file -> closeFileHandle fileendThe mode is a FileMode ADT (Prelude): Read, Write, ReadWrite, Append.
closeFileHandle : FileHandle -> ()
Section titled “closeFileHandle : FileHandle -> ()”Close a file handle.
readBytes : FileHandle -> Int -> ByteArray
Section titled “readBytes : FileHandle -> Int -> ByteArray”Read up to count bytes from a file handle. Async (io_uring).
Returns a byte buffer.
readExact : FileHandle -> Int -> Result (String, String)
Section titled “readExact : FileHandle -> Int -> Result (String, String)”Read exactly count bytes from an unwrapped typed file handle. Returns Ok
with the bytes, or Err if EOF arrives early or the count is invalid.
readExactBytes : FileHandle -> Int -> String
Section titled “readExactBytes : FileHandle -> Int -> String”Read up to count bytes from an unwrapped typed file handle, returning a short
string at EOF. Use Std\Io.readExactBytes for raw pipe, socket, or console
descriptors.
writeBytes : FileHandle -> ByteArray -> Int
Section titled “writeBytes : FileHandle -> ByteArray -> Int”Write bytes to a file handle. Async (io_uring). Returns the number of bytes written.
seek : FileHandle -> Int -> Whence -> Int
Section titled “seek : FileHandle -> Int -> Whence -> Int”Seek to a position in a file. whence is a Whence ADT (Prelude):
SeekSet (absolute), SeekCur (relative to current), SeekEnd (relative to end).
Returns the new position.
import openFile, seek, tell from Std\File incase openFile "data.bin" Read of Linear file -> seek file 100 SeekSetendtell : FileHandle -> Int
Section titled “tell : FileHandle -> Int”Returns the current position in a file handle.
flush : FileHandle -> Bool
Section titled “flush : FileHandle -> Bool”Flush buffered writes for a file handle. Returns true on success.
truncate : FileHandle -> Int -> Bool
Section titled “truncate : FileHandle -> Int -> Bool”Truncate a file to the given length. Returns true on success.
readChunks : FileHandle -> Int -> Iterator ByteArray
Section titled “readChunks : FileHandle -> Int -> Iterator ByteArray”Read data from a file handle in chunks of chunkSize bytes.
Returns a handle for chunked reading.