src/file.bend checks
raw source on the hub · import snap@1.2.0.0/src/file.bend as MFile
src/file: a file's text, read whole, or None when it cannot be opened.
1 import
import Base
Definitions
def file.slurp.end source · line 5 · raw
@file:File -> @acc:String -> IO(String)
the handle closed, and whatever was gathered
def file.slurp.cut source · line 11 · raw
@chunk:String -> @file:File -> @acc:String -> @rest:(@_:File -> @_:String -> IO(String)) -> IO(String)
an empty chunk means the end of the file
def file.slurp.more source · line 19 · 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 file.slurp.next source · line 32 · 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 file.slurp source · line 41 · raw
@fuel:Nat -> @file:File -> @acc:String -> IO(String)
the whole file, read in chunks until one is empty, or the fuel is
def file.unsized source · line 53 · 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
def file.reads.given source · line 57 · raw
@none:Bool -> @bytes:U32 -> Nat
a size of 0 is no size to go by; any other is read to
def file.reads source · line 66 · 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 file.reads.of source · line 70 · raw
@res:Result<&1, &1, Pair(U32, String), U32> -> Nat
the reads the size the host reported allows
def file.read.sized source · line 78 · 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 file.read.opened source · line 83 · 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 file.read source · line 94 · raw
@path:String -> IO(Maybe<&2, String>)
a file's text, or None when it cannot be opened
def file.text_of source · line 100 · raw
@got:Maybe<&2, String> -> String
a file's text, or "" when there is none