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 -> [a]
Section titled “listDir : String -> [a]”List directory contents. Returns a sequence of filenames.
import listDir from Std\File inlistDir "/tmp" # => ["file1.txt", "file2.txt", ...]readLines : String -> Iterator a
Section titled “readLines : String -> Iterator a”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 -> FileHandle
Section titled “openFile : String -> FileMode -> FileHandle”Open a file with the given mode string ("r", "w", "rw", etc.).
Returns a file descriptor (Int).
import openFile, closeFileHandle from Std\File inlet fd = openFile "data.txt" Read incloseFileHandle fdThe mode is a FileMode ADT (Prelude): Read, Write, ReadWrite, Append.
closeFileHandle : Int -> ()
Section titled “closeFileHandle : Int -> ()”Close a file descriptor.
readBytes : Int -> Int -> ByteArray
Section titled “readBytes : Int -> Int -> ByteArray”Read up to count bytes from a file descriptor. Async (io_uring).
Returns a byte buffer.
writeBytes : Int -> Int -> Int
Section titled “writeBytes : Int -> Int -> Int”Write bytes to a file descriptor. Async (io_uring). Returns the number of bytes written.
seek : Int -> Int -> a -> Int
Section titled “seek : Int -> Int -> a -> 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 inlet fd = openFile "data.bin" "r" inseek fd 100 "set"tell : Int -> Int
Section titled “tell : Int -> Int”Returns the current position in a file descriptor.
flush : Int -> Bool
Section titled “flush : Int -> Bool”Flush buffered writes for a file descriptor. Returns true on success.
truncate : Int -> Int -> Bool
Section titled “truncate : Int -> Int -> Bool”Truncate a file to the given length. Returns true on success.
readChunks : Int -> Int -> Iterator a
Section titled “readChunks : Int -> Int -> Iterator a”Read data from a file descriptor in chunks of chunkSize bytes.
Returns a handle for chunked reading.