~/bend-docscommunity

src/io/file.bend checks

raw source on the hub · import 0x886223f5c47e4983fe57d887c034bc7f/src/io/file.bend as MFile

io/file: a whole file read or written in one call. Base gives an open handle and chunked reads; this is the loop over them.

1 import
import Base

Definitions

def slurp.end source · line 6 · raw

@file:File -> @acc:String -> IO(String)

the handle closed, and whatever was gathered

def slurp.cut source · line 12 · raw

@chunk:String -> @file:File -> @acc:String -> @rest:(@_:File -> @_:String -> IO(String)) -> IO(String)

an empty chunk means the end of the file

def slurp.more source · line 20 · raw

@res:Result<&1, &1, Pair(U32, String), String> -> @file:File -> @acc:String -> @rest:(@_:File -> @_:String -> IO(String)) -> IO(String)

a failed read ends the file as surely as an empty one

def slurp.next source · line 33 · raw

@got:Pair(File, Result<&1, &1, Pair(U32, String), String>) -> @acc:String -> @rest:(@_:File -> @_:String -> IO(String)) -> IO(String)

the handle comes back paired with what it read

def slurp source · line 42 · raw

@fuel:Nat -> @file:File -> @acc:String -> IO(String)

the whole file, read in chunks until one is empty, or the fuel is

def read.opened source · line 52 · raw

@res:Result<&1, &1, Pair(U32, String), File> -> IO(Maybe<&2, String>)

what an opened file holds, or nothing when it would not open

def read source · line 62 · raw

@path:String -> IO(Maybe<&2, String>)

a file's text, or None when it cannot be opened

def write.ok source · line 68 · raw

@res:Result<&1, &1, Pair(U32, String), Unit> -> Bool

whether a write reported success

def write.done source · line 76 · raw

@written:Pair(File, Result<&1, &1, Pair(U32, String), Unit>) -> IO(Bool)

a write's outcome, once the handle is shut

def write.opened source · line 83 · raw

@res:Result<&1, &1, Pair(U32, String), File> -> @text:String -> IO(Bool)

the text written to an opened file

def write source · line 93 · raw

@path:String -> @text:String -> IO(Bool)

a file replaced with this text; False when it could not be written

def text_of source · line 99 · raw

@got:Maybe<&2, String> -> String

a file's text, or "" when there is none