src/io/file.bend checks
raw source on the hub · import ezx@1.18.0.0/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 7 · raw
@file:File -> @acc:List<&2, String> -> IO(String)
the handle closed, and whatever was gathered. The chunks are gathered newest first, so each read is one prepend, and put in order once here.
def slurp.cut source · line 13 · raw
@chunk:String -> @file:File -> @acc:List<&2, String> -> @rest:(@_:File -> @_:List<&2, String> -> IO(String)) -> IO(String)
an empty chunk means the end of the file
def slurp.more source · line 26 · raw
@res:Result<&1, &1, Pair(U32, String), String> -> @file:File -> @acc:List<&2, String> -> @rest:(@_:File -> @_:List<&2, String> -> IO(String)) -> IO(String)
a failed read ends the file as surely as an empty one
def slurp.next source · line 39 · raw
@got:Pair(File, Result<&1, &1, Pair(U32, String), String>) -> @acc:List<&2, String> -> @rest:(@_:File -> @_:List<&2, String> -> IO(String)) -> IO(String)
the handle comes back paired with what it read
def slurp source · line 48 · raw
@fuel:Nat -> @file:File -> @acc:List<&2, String> -> IO(String)
the whole file, read in chunks until one is empty, or the fuel is
def unsized source · line 60 · raw
Nat
the reads a file with no size to go by may take: a pipe, a device or a /proc file reports 0 bytes and a file past 4 GiB fails to report, so these are read until they end, up to 100000 reads of 64 KiB, past any file ez reads
def reads.given source · line 64 · raw
@none:Bool -> @bytes:U32 -> Nat
a size of 0 is no size to go by; any other is read to
def reads source · line 73 · raw
@+bytes:U32 -> Nat
the reads a file of this many bytes takes: one for every 64 KiB, one for the part past the last whole 64 KiB, and one to spare for a short read
def reads.of source · line 77 · raw
@res:Result<&1, &1, Pair(U32, String), U32> -> Nat
the reads the size the host reported allows
def read.sized source · line 85 · raw
@got:Pair(File, Result<&1, &1, Pair(U32, String), U32>) -> IO(String)
a file read whole, with fuel enough for the size it reported
def read.opened source · line 90 · 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 101 · raw
@path:String -> IO(Maybe<&2, String>)
a file's text, or None when it cannot be opened
def write.ok source · line 107 · raw
@res:Result<&1, &1, Pair(U32, String), Unit> -> Bool
whether a write reported success
def write.done source · line 115 · 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 122 · raw
@res:Result<&1, &1, Pair(U32, String), File> -> @text:String -> IO(Bool)
the text written to an opened file
def write source · line 132 · 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 138 · raw
@got:Maybe<&2, String> -> String
a file's text, or "" when there is none