flix

0.75.2

Fs.FileRead

eff FileReadSource

An effect used to read file contents (string, lines, bytes).

Operations

def read(f: String): Result[IoError, String] \ FileRead§ Source

Returns a string of all the contents of the given file f.

def readBytes(f: String): Result[IoError, Vector[Int8]] \ FileRead§ Source

Returns a vector of all the bytes in the given file f.

def readLines(f: String): Result[IoError, List[String]] \ FileRead§ Source

Returns a list of all lines in the given file f.

Definitions

def handle(f: a -> b \ ef): a -> b \ (ef - FileRead) + IO§ Source

Handles the FileRead effect of the given function f.

In other words, re-interprets the FileRead effect using the IO effect.

def runWithFileSystem(f: Unit -> a \ ef): a \ (ef - FileRead) + FileSystem§ Source

Handles the FileRead effect of the given function f using the FileSystem effect.

@DefaultHandler
def runWithIO(f: Unit -> a \ ef): a \ (ef - FileRead) + IO§ Source

Runs the FileRead effect of the given function f.

In other words, re-interprets the FileRead effect using the IO effect.

def withAllowGlob(patterns: Nel[String], f: Unit -> a \ ef): a \ (ef - FileRead) + FileRead§ Source

Middleware that intercepts the FileRead effect, validating that all file paths match at least one of the given glob patterns. Rejects paths that do not match with a PermissionDenied error.

def withAllowList(allowedDirs: Nel[String], f: Unit -> a \ ef): a \ (ef - FileRead) + FileRead§ Source

Middleware that intercepts the FileRead effect, validating that all file paths resolve within one of the given allowedDirs. Rejects paths outside the allow list with a PermissionDenied error.

def withBaseDir(baseDir: String, f: Unit -> a \ ef): a \ (ef - FileRead) + FileRead§ Source

Middleware that intercepts the FileRead effect, resolving all file paths relative to the given baseDir using Java's Path.resolve semantics.

Absolute paths are passed through unchanged.

def withChecksum(hash: Vector[Int8] -> Vector[Int8], sidecar: String, f: Unit -> a \ ef): a \ (ef - FileRead) + FileRead§ Source

Middleware that intercepts the FileRead effect, verifying file checksums on read. If a sidecar checksum file exists (e.g., "data.txt.sha256" when sidecar is ".sha256"), the file's contents are hashed and compared against the stored checksum.

hash is a pure function from file bytes to digest bytes. sidecar is the file suffix (e.g., ".sha256").

If no sidecar file exists, the read proceeds normally. If the checksum does not match, returns Err(IoError(ChecksumMismatch, ...)).

def withChroot(chrootDir: String, f: Unit -> a \ ef): a \ (ef - FileRead) + FileRead§ Source

Middleware that intercepts the FileRead effect, validating that all file paths resolve within the given chrootDir. Rejects paths that escape the chroot with a PermissionDenied error.

def withDenyGlob(patterns: Nel[String], f: Unit -> a \ ef): a \ (ef - FileRead) + FileRead§ Source

Middleware that intercepts the FileRead effect, validating that all file paths do not match any of the given glob patterns. Rejects paths that match a denied pattern with a PermissionDenied error.

def withDenyList(deniedDirs: Nel[String], f: Unit -> a \ ef): a \ (ef - FileRead) + FileRead§ Source

Middleware that intercepts the FileRead effect, validating that all file paths do not resolve within any of the given deniedDirs. Rejects paths inside a denied directory with a PermissionDenied error.

def withLogging(f: Unit -> a \ ef): a \ (ef - FileRead) + FileRead + Logger§ Source

Middleware that intercepts the FileRead effect, logging each operation and its result via the Logger effect.

Successful operations are logged at Debug level; errors at Warn.

def withTransferLimit(maxSize: Size, f: Unit -> a \ ef): a \ (ef - FileRead) + FileRead + FileStat§ Source

Middleware that intercepts the FileRead effect, rejecting reads of files larger than maxBytes. The file size is checked via FileStat.size before reading. For string-based reads, the limit applies to the on-disk file size (not the in-memory string length).