files.bend relies on unsafe/foreign
raw source on the hub · import bend-kit-files@0.4.0.2/files.bend as Files
POSIX paths plus directory and metadata effects. Source: https://github.com/paymog/bend-kit/tree/main/files
2 imports
import Base import bend-kit-bytes@0.3.3.2/bytes.bend as Bytes
Types
type FileType source · line 129 · raw
Data
RegularFileType
DirectoryFileType
OtherFileType
type Info source · line 135 · raw
Data
size and whole Unix seconds are (hi, lo), each with 64 bits.
Info@kind:FileType -> @size:Sigma<&2, &2, U32, _ => U32> -> @mtime:Sigma<&2, &2, U32, _ => U32> -> Info
Definitions
def path.is_absolute source · line 9 · raw
@p:String -> Bool
def path.join.rel source · line 12 · raw
@bare:Bool -> @a:String -> @b:String -> String
def path.join.if source · line 19 · raw
@abs:Bool -> @+a:String -> @b:String -> String
def path.join source · line 27 · raw
@a:String -> @+b:String -> String
b when b is absolute; otherwise b under a.
def path.norm.pop.if source · line 30 · raw
@up:Bool -> @h:String -> @t:List<&2, String> -> List<&2, String>
def path.norm.pop source · line 39 · raw
@stack:List<&2, String> -> @abs:Bool -> List<&2, String>
A ".." above the root is dropped; above a relative start it is kept.
def path.norm.step source · line 46 · raw
@skip:Bool -> @up:Bool -> @s:String -> @stack:List<&2, String> -> @abs:Bool -> List<&2, String>
def path.norm.go source · line 60 · raw
@segs:List<&2, String> -> @stack:List<&2, String> -> @+abs:Bool -> List<&2, String>
The kept segments, last first.
def path.norm.fin source · line 71 · raw
@abs:Bool -> @body:String -> String
def path.normalize source · line 84 · raw
@+p:String -> String
Drops empty and "." segments and resolves "..", as POSIX normpath does (RFC 3986 §5.2.4 for paths), but always to one leading "/".
def path.parent source · line 90 · raw
@p:String -> String
def path.file_name.fin source · line 96 · raw
@m:Maybe<&2, String> -> String
def path.file_name source · line 104 · raw
@p:String -> String
The last segment of the normalized path; "" for "/" and ".".
def path.extension.fin source · line 107 · raw
@bare:Bool -> @ext:String -> String
def path.extension.go source · line 114 · raw
@rev:List<&2, String> -> String
def path.extension source · line 126 · raw
@p:String -> String
The text after the file name's last ".", without the dot. A leading dot does not start one: ".bashrc" has none.
def read_bytes.wrap source · line 188 · raw
@result:Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)> -> Result<&1, &1, Pair(U32, String), 0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes>
def read_bytes.pair source · line 196 · raw
@pair:Pair(File, Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)>) -> Pair(File, Result<&1, &1, Pair(U32, String), 0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes>)
def read_bytes source · line 203 · raw
@file:File -> @max:U32 -> IO(Pair(File, Result<&1, &1, Pair(U32, String), 0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes>))
The existing Bytes layout, without an octet List or String.
def write_bytes source · line 216 · raw
@file:File -> @data:0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes -> IO(Pair(File, Result<&1, &1, Pair(U32, String), Unit>))
def list_dir.fin source · line 221 · raw
@r:Result<&1, &1, Pair(U32, String), String> -> Result<&1, &1, Pair(U32, String), List<&2, String>>
def list_dir source · line 232 · raw
@path:String -> IO(Result<&1, &1, Pair(U32, String), List<&2, String>>)
Entry names, without "." and "..", sorted.
def stat.kind source · line 238 · raw
@+k:U32 -> FileType
def stat.fin source · line 242 · raw
@r:Result<&1, &1, Pair(U32, String), Pair(U32, Pair(Pair(U32, U32), Pair(U32, U32)))> -> Result<&1, &1, Pair(U32, String), Info>
def stat source · line 250 · raw
@path:String -> IO(Result<&1, &1, Pair(U32, String), Info>)
def exists source · line 255 · raw
@path:String -> IO(Bool)
def mkdir_all.dir source · line 260 · raw
@r:Result<&1, &1, Pair(U32, String), Info> -> Result<&1, &1, Pair(U32, String), Unit>
def mkdir_all.fail source · line 270 · raw
@exists:Bool -> @e:Pair(U32, String) -> @k:IO(Result<&1, &1, Pair(U32, String), Unit>) -> IO(Result<&1, &1, Pair(U32, String), Unit>)
def mkdir_all.step source · line 279 · raw
@r:Result<&1, &1, Pair(U32, String), Unit> -> @k:IO(Result<&1, &1, Pair(U32, String), Unit>) -> IO(Result<&1, &1, Pair(U32, String), Unit>)
def mkdir_all.go source · line 288 · raw
@segs:List<&2, String> -> @+at:String -> IO(Result<&1, &1, Pair(U32, String), Unit>)
def mkdir_all source · line 303 · raw
@+path:String -> IO(Result<&1, &1, Pair(U32, String), Unit>)
Creates the directory and any missing parents. Succeeds when it is already a directory; fails if a component is not a directory.
Effects (foreign code)
effect list_dir.raw source · line 139 · raw
@path:String -> IO(Result<&1, &1, Pair(U32, String), String>)
Entry names, NUL-separated, in the order the OS gives them.
foreign: effs/files.c, effs/files.js
effect stat.raw source · line 145 · raw
@path:String -> IO(Result<&1, &1, Pair(U32, String), Pair(U32, Pair(Pair(U32, U32), Pair(U32, U32)))>)
(kind, size, mtime); kind 0 is a regular file, 1 a directory, 2 other. Symbolic links are followed.
foreign: effs/files.c, effs/files.js
effect mkdir source · line 150 · raw
@path:String -> IO(Result<&1, &1, Pair(U32, String), Unit>)
foreign: effs/files.c, effs/files.js
effect remove source · line 155 · raw
@path:String -> IO(Result<&1, &1, Pair(U32, String), Unit>)
Removes a file or an empty directory.
foreign: effs/files.c, effs/files.js
effect rename source · line 159 · raw
@from:String -> @to:String -> IO(Result<&1, &1, Pair(U32, String), Unit>)
foreign: effs/files.c, effs/files.js
effect temp_dir source · line 165 · raw
IO(Result<&1, &1, Pair(U32, String), String>)
Creates a new, empty, private directory under the system temp dir.
foreign: effs/files.c, effs/files.js
effect read.words source · line 171 · raw
@file:File -> @max:U32 -> IO(Pair(File, Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)>))
A successful zero-length read is EOF (or max = 0). Reads at most 1 MiB per call; a short read is not necessarily EOF. Errors retain the File.
foreign: effs/files.c, effs/files.js
effect size64 source · line 177 · raw
@file:File -> IO(Pair(File, Result<&1, &1, Pair(U32, String), Pair(U32, U32)>))
The size of an open file as (hi, lo): hi * 2^32 + lo bytes. Errors retain the File.
foreign: effs/files.c, effs/files.js
effect read.words.at source · line 183 · raw
@file:File -> @hi:U32 -> @lo:U32 -> @max:U32 -> IO(Pair(File, Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)>))
read.words at byte offset hi * 2^32 + lo. The file position does not move.
foreign: effs/files.c, effs/files.js
effect write.words source · line 211 · raw
@file:File -> @len:U32 -> @words:Array<U32> -> IO(Pair(File, Result<&1, &1, Pair(U32, String), Unit>))
Writes the entire buffer or fails. Errors retain the File; writes before an error are not rolled back. A len beyond the word array fails EINVAL.
foreign: effs/files.c, effs/files.js