~/bend-docscommunity

checkpoint_zip.bend checks

raw source on the hub · import stelliferous@0.0.3.0/checkpoint_zip.bend as Checkpoint_zip

A ZIP archive read through the official File effects. The end record locates the central directory, which names every entry with its size and the offset of its local header; the entry's bytes follow that header. Only stored entries are read, the form torch.save writes.

2 imports
import Base
import ./storage_bytes.bend as Bytes

Types

type Record source · line 10 · raw

Data

An entry: its name as bytes, the offset of its local header, its length and its compression method, 0 for stored.

type Listing source · line 13 · raw

Data

type Fetched source · line 17 · raw

Type

Definitions

def Read source · line 20 · raw

Type

def Sized source · line 23 · raw

Type

def central_signature source · line 27 · raw

U32

Signatures, least significant byte first.

def local_signature source · line 30 · raw

U32

def end_signature source · line 33 · raw

List<&2, U32>

def records source · line 37 · raw

@fuel:Nat -> @valid:Bool -> @+bytes:List<&2, U32> -> @found:List<&2, Record> -> Listing

A central directory entry is 46 bytes, then its name, extra field and comment.

def directory_read source · line 48 · raw

@result:Result<&1, &1, Pair(U32, String), List<&2, U32>> -> @+count:U32 -> Listing

def directory_fetched source · line 53 · raw

@read:Read -> @+count:U32 -> Pair(File, Listing)

def ending source · line 57 · raw

@wide:Bool -> @file:File -> @+count:U32 -> @+size:U32 -> @+offset:U32 -> IO(Pair(File, Listing))

def end_found source · line 67 · raw

@found:Maybe<&2, U32> -> @+tail:List<&2, U32> -> @file:File -> IO(Pair(File, Listing))

The end record: entry count at byte 10, directory size at 12 and offset at 16. A count or an offset of all ones means ZIP64, which a 32-bit file never needs.

def tail_read source · line 76 · raw

@result:Result<&1, &1, Pair(U32, String), List<&2, U32>> -> @file:File -> IO(Pair(File, Listing))

def tail_fetched source · line 81 · raw

@read:Read -> IO(Pair(File, Listing))

def measured source · line 86 · raw

@result:Result<&1, &1, Pair(U32, String), U32> -> @file:File -> IO(Pair(File, Listing))

The end record is 22 bytes plus a comment of at most 65535.

def sized source · line 95 · raw

@sized:Sized -> IO(Pair(File, Listing))

def directory source · line 100 · raw

@file:File -> IO(Pair(File, Listing))

The entries of an open file, in directory order.

def find source · line 105 · raw

@records:List<&2, Record> -> @+name:List<&2, U32> -> Maybe<&2, Record>

def first_matching source · line 111 · raw

@records:List<&2, Record> -> @+suffix:List<&2, U32> -> Maybe<&2, Record>

def located source · line 118 · raw

@valid:Bool -> @+bytes:List<&2, U32> -> @+header:U32 -> Maybe<&2, U32>

The local header is 30 bytes, then the name and the extra field; the data follows.

def header_read source · line 123 · raw

@result:Result<&1, &1, Pair(U32, String), List<&2, U32>> -> @+header:U32 -> Maybe<&2, U32>

def header_fetched source · line 128 · raw

@read:Read -> @+header:U32 -> Pair(File, Maybe<&2, U32>)

def stored_offset source · line 133 · raw

@stored:Bool -> @file:File -> @+header:U32 -> IO(Pair(File, Maybe<&2, U32>))

The offset of the first byte of a stored entry. A compressed entry has none.

def data_offset source · line 141 · raw

@file:File -> @+record:Record -> IO(Pair(File, Maybe<&2, U32>))

def entry_read source · line 145 · raw

@result:Result<&1, &1, Pair(U32, String), List<&2, U32>> -> @+length:U32 -> Maybe<&2, List<&2, U32>>

def entry_fetched source · line 150 · raw

@read:Read -> @+length:U32 -> Fetched

def entry_at source · line 154 · raw

@offset:Maybe<&2, U32> -> @file:File -> @+length:U32 -> IO(Fetched)

def entry_located source · line 162 · raw

@located:Pair(File, Maybe<&2, U32>) -> @+length:U32 -> IO(Fetched)

def entry source · line 167 · raw

@file:File -> @+record:Record -> IO(Fetched)

Every byte of a stored entry in one read, for small entries.