~/bend-docscommunity

ustar.bend relies on unsafe/foreign

raw source on the hub · import gralha-ustar@0.1.0.0/ustar.bend as Ustar

gralha-ustar: POSIX ustar archives over gralha-byte-words. header builds a member's 512-byte header; create_stream writes an archive member by member; manifest and fill produce the archive into bounded Sink batches (for a compressor); walk lists or extracts an archive held in memory, and list_file lists one from an open file, reading only its headers. Regular files only: mode 0644, uid and gid 0, mtime 0.

2 imports
import Base
import gralha-byte-words@0.1.0.0/words.bend as Words

Types

type Tm source · line 197 · raw

Type

The bounded gzip source. Metadata is collected once, then the logical tar stream is produced into fixed batches without constructing a whole archive.

type Gsrc source · line 212 · raw

Type

type Bt source · line 219 · raw

Type

type Hdr source · line 318 · raw

Type

type Hs2 source · line 322 · raw

Type

the bytes [off, off+n) as a string, reversed onto acc

type Hz source · line 345 · raw

Type

whether the 128 words at off are zero

type Ls source · line 440 · raw

Type

Plain archives are listed one header at a time. Payload ranges are skipped by advancing the pread offset, so a one-file 64 MiB archive reads 512 bytes rather than materializing all 64 MiB. Gzip still uses the decoder above.

Definitions

def b2u source · line 14 · raw

@b:Bool -> U32

def pick source · line 21 · raw

@c:Bool -> @a:U32 -> @b:U32 -> U32

def slen source · line 28 · raw

@s:String -> @+acc:U32 -> U32

def srev source · line 36 · raw

@s:String -> @acc:String -> String

reverse onto acc

def sdrop source · line 43 · raw

@n:Nat -> @s:String -> String

def stake_rev source · line 53 · raw

@n:Nat -> @s:String -> @acc:String -> String

the first n bytes, reversed onto acc

def stake source · line 62 · raw

@n:Nat -> @s:String -> String

def split_at source · line 66 · raw

@n:Nat -> @s:String -> @acc:String -> Pair(String, String)

the first n bytes and the rest

def srev_len source · line 76 · raw

@s:String -> @acc:String -> @+n:U32 -> Pair(String, U32)

reverse onto acc, counting

def sfill source · line 84 · raw

@n:Nat -> @+c:U32 -> @s:String -> String

n copies of byte c in front of s

def field source · line 92 · raw

@+n:U32 -> @+s:String -> String

s cut or NUL-padded to exactly n bytes

def head_is source · line 104 · raw

@s:String -> @+c:U32 -> Bool

def head_digit source · line 107 · raw

@s:String -> Bool

def cstr source · line 112 · raw

@s:String -> @acc:String -> @nul:Bool -> String

the bytes of s up to the first NUL; nul says whether s starts with one

def sat source · line 123 · raw

@s:String -> @i:Nat -> U32

the byte at position i, 0 past the end

def octal source · line 133 · raw

@n:Nat -> @+v:U32 -> @tail:String -> String

n digits of v in octal, least significant first, in front of tail

def unoctal source · line 141 · raw

@s:String -> @+acc:U32 -> @digit:Bool -> U32

an octal field read while digits last; digit says whether s starts with one

def ssum source · line 151 · raw

@s:String -> @+acc:U32 -> U32

def all_zero source · line 158 · raw

@s:String -> @ok:Bool -> Bool

def le32 source · line 165 · raw

@+v:U32 -> String

def say source · line 168 · raw

@verbose:Bool -> @line:String -> IO(Unit)

def padding source · line 182 · raw

@+n:U32 -> U32

def manifest source · line 200 · raw

@names:List<&2, String> -> @+verbose:Bool -> IO(List<&1, Tm>)

def gs_data_next source · line 222 · raw

@+name:String -> @+size:U32 -> @+at:U32 -> @rest:List<&1, Tm> -> @done:Bool -> Gsrc

def gs_pad_next source · line 229 · raw

@rest:List<&1, Tm> -> @+left:U32 -> @done:Bool -> Gsrc

def gs_zero_next source · line 236 · raw

@+left:U32 -> @done:Bool -> Gsrc

def fill source · line 245 · raw

@fuel:Nat -> @more:Bool -> @src:Gsrc -> @ob:0x365c60316ea66a6c80658fc03b4eeac5/words.Sink -> @+limit:U32 -> IO(Bt)

At most 4096 command-line words enter the parser. A batch can therefore cross every member header, body, and padding run without an artificial early flush.

def stream_ob source · line 290 · raw

@+out:String -> @+input:String -> @+pad:U32 -> @first:Bool -> @st:0x365c60316ea66a6c80658fc03b4eeac5/words.Sink -> IO(Unit)

The plain create path writes one member at a time. Headers stay in Bend; the effect only transfers their packed words and copies the file into the ordered sink, so member contents never enter the growing archive Array.

def stream_member source · line 295 · raw

@+out:String -> @+name:String -> @+size:U32 -> @first:Bool -> IO(Unit)

def stream_end source · line 298 · raw

@+out:String -> @first:Bool -> IO(Unit)

def create_stream source · line 301 · raw

@names:List<&2, String> -> @+verbose:Bool -> @+out:String -> @first:Bool -> IO(Unit)

def hs_cons source · line 325 · raw

@r:Pair(Array<U32>, U32) -> @acc:String -> Hs2

def hs_loop source · line 329 · raw

@n:Nat -> @st:Hs2 -> @+j:U32 -> Hs2

def hs_of source · line 336 · raw

@st:Hs2 -> Pair(Array<U32>, String)

def bytes_str source · line 341 · raw

@a:Array<U32> -> @+off:U32 -> @+n:U32 -> Pair(Array<U32>, String)

def hz_at source · line 348 · raw

@r:Pair(Array<U32>, U32) -> @zero:Bool -> Hz

def hz_loop source · line 352 · raw

@n:Nat -> @st:Hz -> @+q:U32 -> Hz

def hz_of source · line 359 · raw

@st:Hz -> Pair(Array<U32>, Bool)

def hdr_kind source · line 364 · raw

@r:Pair(Array<U32>, U32) -> @name:String -> @+size:U32 -> @+off:U32 -> Hdr

def hdr_size source · line 368 · raw

@r:Pair(Array<U32>, String) -> @name:String -> @+off:U32 -> Hdr

def hdr_name source · line 373 · raw

@r:Pair(Array<U32>, String) -> @+off:U32 -> Hdr

def hdr_live source · line 378 · raw

@r:Pair(Array<U32>, Bool) -> @+off:U32 -> Hdr

def hdr_go source · line 386 · raw

@a:Array<U32> -> @+off:U32 -> @past:Bool -> Hdr

def header_at source · line 393 · raw

@a:Array<U32> -> @+off:U32 -> @+n:U32 -> Hdr

def tar_write source · line 396 · raw

@a:Array<U32> -> @+name:String -> @+off:U32 -> @+size:U32 -> @verbose:Bool -> @dir:Bool -> IO(Array<U32>)

def tar_emit source · line 407 · raw

@a:Array<U32> -> @+name:String -> @+off:U32 -> @+size:U32 -> @kind:U32 -> @extract:Bool -> @verbose:Bool -> IO(Array<U32>)

def walk_loop source · line 417 · raw

@fuel:Nat -> @h:Hdr -> @+n:U32 -> @+extract:Bool -> @+verbose:Bool -> IO(Unit)

walks the entries; fuel bounds the loop by the archive's block count

def walk source · line 432 · raw

@r:Pair(Array<U32>, U32) -> @extract:Bool -> @verbose:Bool -> IO(Unit)

def ls_read source · line 444 · raw

@r:0x365c60316ea66a6c80658fc03b4eeac5/words.Chunk -> @+off:U32 -> Ls

def list_stream_close source · line 449 · raw

@st:Ls -> IO(Unit)

def list_stream_loop source · line 460 · raw

@fuel:Nat -> @st:Ls -> @+path:String -> @+n:U32 -> IO(Unit)

def list_file source · line 485 · raw

@file:File -> @a:Array<U32> -> @+got:U32 -> @+path:String -> @+n:U32 -> IO(Unit)

lists the archive in file (n bytes) to stdout, given its first chunk: a, read at offset 0, got bytes long; only the headers are read