zlib.bend relies on unsafe/foreign
raw source on the hub · import bend-kit-zlib@0.5.0.0/zlib.bend as Zlib
DEFLATE, gzip, and zlib encoding and decoding (RFC 1951, 1952, 1950) over Bytes, plus gzip, zstd, and brotli through the C libraries. Source: https://github.com/paymog/bend-kit/tree/main/zlib
4 imports
import Base import bend-kit-bytes@0.3.3.0/bytes.bend as Bytes import bend-kit-bits@0.1.0.0/bits.bend as Bits import bend-kit-hash@0.3.0.1/hash.bend as Hash
Types
type Br source · line 11 · raw
Type
Bit reader. bad: a read ran past the end, so the input was cut short.
Br@r:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Reader -> @bad:Bool -> Br
type Out source · line 101 · raw
Type
Output: 2^dep words of packed bytes, n of them written. Matches copy from the output itself.
Out@buf:Array<U32> -> @dep:U32 -> @n:U32 -> Out
type Mo source · line 147 · raw
Type
MoHeadMo
MoCodes@lit:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> @dist:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> Mo
MoDoneMo
MoBadMo
type Is source · line 153 · raw
Type
Is@br:Br -> @o:Out -> @mode:Mo -> @last:Bool -> Is
type Cd source · line 229 · raw
Type
The code-length code, lengths so far (reversed), how many, the last one (for code 16), and whether it went wrong.
Cd@h:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> @br:Br -> @acc:List<&2, U32> -> @n:U32 -> @prev:U32 -> @bad:Bool -> Cd
type Inflated source · line 485 · raw
Type
out: the bytes; src: the input back; at: the first byte after the stream.
Inflated@out:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> @src:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> @at:U32 -> Inflated
type Cx source · line 733 · raw
Data
The last index whose base is at most v, with that base and its extra-bit count; bases ascend.
Cx@i:U32 -> @base:U32 -> @extra:U32 -> Cx
type Lz source · line 763 · raw
Type
Match finder: the input bytes, packed, the newest position + 1 per hash, and per position the previous one with its hash (0: none).
Lz@src:Array<U32> -> @head:Array<U32> -> @prev:Array<U32> -> Lz
type Ml source · line 807 · raw
Type
Match length: bytes at a + k and b + k compared so far, and whether the last pair was equal.
Ml@z:Lz -> @a:U32 -> @b:U32 -> @k:U32 -> @eq:Bool -> Ml
type Ch source · line 840 · raw
Type
Chain walk at i: candidate c (position + 1), the longest match so far, and whether to go on.
Ch@z:Lz -> @i:U32 -> @c:U32 -> @max:U32 -> @blen:U32 -> @bdist:U32 -> @go:Bool -> Ch
type Es source · line 871 · raw
Type
Encoder: match finder, bit writer, position, input length, and whether bytes are left.
Es@z:Lz -> @w:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Writer -> @i:U32 -> @n:U32 -> @more:Bool -> Es
type Decoder source · line 1032 · raw
Type
A live native decoder. Call dec.finish even after a failed feed to release it.
Decoder@id:U32 -> Decoder
Definitions
def bits source · line 7 · raw
@+n:U32 -> Nat
def br.got source · line 14 · raw
@+bad:Bool -> @rm:Pair(0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Reader, Maybe<&2, U32>) -> Pair(Br, U32)
def br.take source · line 22 · raw
@b:Br -> @+n:U32 -> Pair(Br, U32)
def br.sym.got source · line 27 · raw
@+bad:Bool -> @r:Pair(0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff, Pair(0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Reader, Maybe<&2, U32>)) -> Pair(0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff, Pair(Br, U32))
No code: 9999, never a symbol.
def br.sym source · line 35 · raw
@h:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> @b:Br -> Pair(0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff, Pair(Br, U32))
def br.align source · line 40 · raw
@b:Br -> Br
RFC 1951 §3.2.4: a stored block starts on a byte boundary.
def nth source · line 44 · raw
@xs:List<&2, U32> -> @+i:U32 -> U32
def rep source · line 51 · raw
@k:Nat -> @+v:U32 -> @acc:List<&2, U32> -> List<&2, U32>
def take.n source · line 58 · raw
@k:Nat -> @xs:List<&2, U32> -> List<&2, U32>
def drop.n source · line 69 · raw
@k:Nat -> @xs:List<&2, U32> -> List<&2, U32>
def len.base source · line 81 · raw
List<&2, U32>
RFC 1951 §3.2.5
def len.extra source · line 84 · raw
List<&2, U32>
def dist.base source · line 87 · raw
List<&2, U32>
def dist.extra source · line 90 · raw
List<&2, U32>
def fixed.lit source · line 94 · raw
Maybe<&1, 0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff>
RFC 1951 §3.2.6
def fixed.dist source · line 97 · raw
Maybe<&1, 0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff>
def out.fits source · line 104 · raw
@+dep:U32 -> @+want:U32 -> Bool
def out.dep source · line 107 · raw
@f:Nat -> @fits:Bool -> @+dep:U32 -> @+want:U32 -> U32
def out.grow source · line 119 · raw
@fits:Bool -> @o:Out -> @+want:U32 -> Out
def out.room source · line 130 · raw
@o:Out -> @+k:U32 -> Out
The buffer doubles until k more bytes fit, so output is O(total), and it ends as the fewest 2^dep words that hold n, as Bytes expects.
def out.put source · line 135 · raw
@o:Out -> @+c:U32 -> Out
def out.size source · line 139 · raw
@o:Out -> Pair(Out, U32)
def out.bytes source · line 143 · raw
@o:Out -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes
def inf.next source · line 156 · raw
@last:Bool -> Mo
def inf.bad source · line 163 · raw
@b:Br -> @o:Out -> Is
def sb.put source · line 167 · raw
@bv:Pair(Br, U32) -> @o:Out -> Pair(Br, Out)
Stored block (§3.2.4): LEN, then NLEN (its complement), then LEN raw bytes.
def sb.go source · line 171 · raw
@k:Nat -> @st:Pair(Br, Out) -> Pair(Br, Out)
def sb.done source · line 179 · raw
@st:Pair(Br, Out) -> @+last:Bool -> Is
def sb.ok source · line 183 · raw
@ok:Bool -> @b:Br -> @+len:U32 -> @o:Out -> @+last:Bool -> Is
def sb.nlen source · line 190 · raw
@bv:Pair(Br, U32) -> @+len:U32 -> @o:Out -> @+last:Bool -> Is
def sb.len source · line 194 · raw
@bv:Pair(Br, U32) -> @o:Out -> @+last:Bool -> Is
def inf.stored source · line 198 · raw
@b:Br -> @o:Out -> @+last:Bool -> Is
def cl.slot source · line 203 · raw
List<&2, U32>
Dynamic block (§3.2.7): code lengths for the code-length code, then the lengths themselves. cl.slot[i]: where symbol i's length sits in the order the stream sends them.
def cl.place source · line 206 · raw
@xs:List<&2, U32> -> @+vals:List<&2, U32> -> List<&2, U32>
def cl.push source · line 213 · raw
@bv:Pair(Br, U32) -> @acc:List<&2, U32> -> Pair(Br, List<&2, U32>)
def cl.one source · line 217 · raw
@st:Pair(Br, List<&2, U32>) -> Pair(Br, List<&2, U32>)
def cl.read source · line 221 · raw
@k:Nat -> @st:Pair(Br, List<&2, U32>) -> Pair(Br, List<&2, U32>)
def cd.fill source · line 232 · raw
@over:Bool -> @h:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> @b:Br -> @acc:List<&2, U32> -> @+n:U32 -> @+v:U32 -> @+cnt:U32 -> Cd
def cd.rep source · line 239 · raw
@h:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> @bv:Pair(Br, U32) -> @+v:U32 -> @+base:U32 -> @acc:List<&2, U32> -> @+n:U32 -> @+total:U32 -> Cd
def cd.prev source · line 244 · raw
@ok:Bool -> @h:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> @b:Br -> @acc:List<&2, U32> -> @+n:U32 -> @+prev:U32 -> @+total:U32 -> Cd
def cd.z18 source · line 251 · raw
@ok:Bool -> @h:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> @b:Br -> @acc:List<&2, U32> -> @+n:U32 -> @+total:U32 -> Cd
def cd.z17 source · line 258 · raw
@ok:Bool -> @h:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> @b:Br -> @acc:List<&2, U32> -> @+n:U32 -> @+s:U32 -> @+total:U32 -> Cd
def cd.c16 source · line 265 · raw
@ok:Bool -> @h:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> @b:Br -> @acc:List<&2, U32> -> @+n:U32 -> @+prev:U32 -> @+s:U32 -> @+total:U32 -> Cd
def cd.lit source · line 272 · raw
@ok:Bool -> @h:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> @b:Br -> @acc:List<&2, U32> -> @+n:U32 -> @+prev:U32 -> @+s:U32 -> @+total:U32 -> Cd
def cd.sym.at source · line 280 · raw
@h:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> @b:Br -> @+s:U32 -> @acc:List<&2, U32> -> @+n:U32 -> @+prev:U32 -> @+total:U32 -> Cd
A + binder in a nested tuple does not check (bendlang/bend#1077), so a helper takes it.
def cd.sym source · line 283 · raw
@r:Pair(0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff, Pair(Br, U32)) -> @acc:List<&2, U32> -> @+n:U32 -> @+prev:U32 -> @+total:U32 -> Cd
def cd.step source · line 287 · raw
@stop:Bool -> @h:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> @b:Br -> @acc:List<&2, U32> -> @+n:U32 -> @+prev:U32 -> @+bad:Bool -> @+total:U32 -> Cd
def cd.go source · line 295 · raw
@k:Nat -> @+total:U32 -> @st:Cd -> Cd
Each step adds at least one length, so total steps suffice.
def dyn.dist source · line 303 · raw
@lit:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> @m:Maybe<&1, 0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff> -> Mo
def dyn.mo source · line 310 · raw
@l:Maybe<&1, 0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff> -> @d:Maybe<&1, 0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff> -> Mo
def dyn.tables source · line 317 · raw
@bad:Bool -> @b:Br -> @+lens:List<&2, U32> -> @+hlit:U32 -> Pair(Br, Mo)
def dyn.done source · line 324 · raw
@st:Cd -> @+hlit:U32 -> @+total:U32 -> Pair(Br, Mo)
def dyn.cl source · line 328 · raw
@m:Maybe<&1, 0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff> -> @b:Br -> @+hlit:U32 -> @+total:U32 -> Pair(Br, Mo)
def dyn.lens source · line 335 · raw
@st:Pair(Br, List<&2, U32>) -> @+hlit:U32 -> @+hdist:U32 -> Pair(Br, Mo)
def dyn.clen source · line 339 · raw
@bv:Pair(Br, U32) -> @+hlit:U32 -> @+hdist:U32 -> Pair(Br, Mo)
def dyn.hdist source · line 343 · raw
@bv:Pair(Br, U32) -> @+hlit:U32 -> Pair(Br, Mo)
def dyn.hlit source · line 347 · raw
@bv:Pair(Br, U32) -> Pair(Br, Mo)
def dyn.read source · line 351 · raw
@b:Br -> Pair(Br, Mo)
def cp.of source · line 356 · raw
@+dep:U32 -> @+n:U32 -> @r:Pair(Array<U32>, U32) -> Out
A match copies len bytes from d back in the output, one at a time, so it may overlap itself. ponytail: byte-at-a-time copy; use Bytes.copy when d >= len if long matches dominate.
def cp.one source · line 360 · raw
@+d:U32 -> @o:Out -> Out
def cp.go source · line 364 · raw
@k:Nat -> @+d:U32 -> @o:Out -> Out
def inf.far source · line 372 · raw
@ok:Bool -> @lit:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> @dist:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> @b:Br -> @+len:U32 -> @+d:U32 -> @o:Out -> @+last:Bool -> Is
RFC 1951 §3.2.5: a distance may not reach before the first byte out.
def inf.dn source · line 379 · raw
@lit:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> @dist:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> @b:Br -> @+len:U32 -> @+d:U32 -> @r:Pair(Out, U32) -> @+last:Bool -> Is
def inf.dx source · line 383 · raw
@bv:Pair(Br, U32) -> @+db:U32 -> @+len:U32 -> @lit:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> @dist:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> @o:Out -> @+last:Bool -> Is
def inf.ds source · line 387 · raw
@ok:Bool -> @lit:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> @dist:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> @b:Br -> @+ds:U32 -> @+len:U32 -> @o:Out -> @+last:Bool -> Is
def inf.d.at source · line 395 · raw
@dist:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> @b:Br -> @+ds:U32 -> @+len:U32 -> @lit:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> @o:Out -> @+last:Bool -> Is
A + binder in a nested tuple does not check (bendlang/bend#1077), so a helper takes it.
def inf.d source · line 398 · raw
@r:Pair(0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff, Pair(Br, U32)) -> @+len:U32 -> @lit:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> @o:Out -> @+last:Bool -> Is
def inf.lx source · line 402 · raw
@bv:Pair(Br, U32) -> @+lb:U32 -> @lit:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> @dist:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> @o:Out -> @+last:Bool -> Is
def inf.ls source · line 406 · raw
@ok:Bool -> @lit:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> @dist:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> @b:Br -> @+s:U32 -> @o:Out -> @+last:Bool -> Is
def inf.end source · line 414 · raw
@eob:Bool -> @lit:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> @dist:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> @b:Br -> @+s:U32 -> @o:Out -> @+last:Bool -> Is
def inf.lit source · line 421 · raw
@ok:Bool -> @lit:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> @dist:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> @b:Br -> @+s:U32 -> @o:Out -> @+last:Bool -> Is
def inf.sym.at source · line 429 · raw
@lit:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> @b:Br -> @+s:U32 -> @dist:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> @o:Out -> @+last:Bool -> Is
A + binder in a nested tuple does not check (bendlang/bend#1077), so a helper takes it.
def inf.sym source · line 432 · raw
@r:Pair(0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff, Pair(Br, U32)) -> @dist:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Huff -> @o:Out -> @+last:Bool -> Is
def inf.dyn source · line 436 · raw
@bm:Pair(Br, Mo) -> @o:Out -> @+last:Bool -> Is
def inf.t2 source · line 440 · raw
@is2:Bool -> @b:Br -> @o:Out -> @+last:Bool -> Is
def inf.t1 source · line 447 · raw
@is1:Bool -> @b:Br -> @o:Out -> @+last:Bool -> @+t:U32 -> Is
def inf.t0 source · line 454 · raw
@is0:Bool -> @b:Br -> @o:Out -> @+last:Bool -> @+t:U32 -> Is
def inf.head source · line 462 · raw
@bv:Pair(Br, U32) -> @o:Out -> Is
§3.2.3: BFINAL, then BTYPE.
def inf.go source · line 468 · raw
@k:Nat -> @st:Is -> Is
Every step reads at least one bit or fails, so 8 steps per input byte always finish a valid stream.
def inf.done source · line 488 · raw
@r:Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, U32) -> @o:Out -> Maybe<&1, Inflated>
def inf.fin source · line 492 · raw
@b:Br -> @o:Out -> Maybe<&1, Inflated>
def inf.result source · line 500 · raw
@st:Is -> Maybe<&1, Inflated>
def inf.start source · line 512 · raw
@ok:Bool -> @+len:U32 -> @buf:Array<U32> -> @+at:U32 -> Maybe<&1, Inflated>
def inflate.at source · line 521 · raw
@b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> @+at:U32 -> Maybe<&1, Inflated>
A raw DEFLATE stream that starts at byte at.
def inflate.out source · line 525 · raw
@m:Maybe<&1, Inflated> -> Maybe<&1, 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes>
def inflate source · line 533 · raw
@b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&1, 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes>
Raw DEFLATE. None: malformed or cut short.
def holds source · line 536 · raw
@m:Maybe<&2, U32> -> @+v:U32 -> Bool
def keep source · line 543 · raw
@ok:Bool -> @b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&1, 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes>
def flag source · line 550 · raw
@+f:U32 -> @+bit:U32 -> Bool
def gz.xlen source · line 555 · raw
@+off:U32 -> @r:Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, Maybe<&2, U32>) -> Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, Maybe<&2, U32>)
RFC 1952 §2.3: after the fixed 10 bytes, optional FEXTRA, FNAME, FCOMMENT, FHCRC. Each step takes the buffer and the offset so far; None once a field runs past the end.
def gz.fextra.at source · line 563 · raw
@m:Maybe<&2, U32> -> @b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, Maybe<&2, U32>)
def gz.fextra source · line 570 · raw
@on:Bool -> @r:Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, Maybe<&2, U32>) -> Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, Maybe<&2, U32>)
def gz.zero source · line 578 · raw
@r:Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, Maybe<&2, U32>) -> Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, Maybe<&2, U32>)
def gz.fstr.at source · line 586 · raw
@m:Maybe<&2, U32> -> @b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, Maybe<&2, U32>)
def gz.fstr source · line 594 · raw
@on:Bool -> @r:Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, Maybe<&2, U32>) -> Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, Maybe<&2, U32>)
A zero-terminated FNAME or FCOMMENT.
def gz.fhcrc.at source · line 602 · raw
@m:Maybe<&2, U32> -> @b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, Maybe<&2, U32>)
def gz.fhcrc source · line 609 · raw
@on:Bool -> @r:Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, Maybe<&2, U32>) -> Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, Maybe<&2, U32>)
def gz.isize source · line 617 · raw
@+ok:Bool -> @+n:U32 -> @out:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> @r:Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, Maybe<&2, U32>) -> Maybe<&1, 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes>
def gz.crc source · line 621 · raw
@r:Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, U32) -> @+n:U32 -> @+at:U32 -> @c:Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, Maybe<&2, U32>) -> Maybe<&1, 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes>
def gz.trail source · line 626 · raw
@m:Maybe<&1, Inflated> -> Maybe<&1, 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes>
def gz.body source · line 634 · raw
@r:Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, Maybe<&2, U32>) -> Maybe<&1, 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes>
def gz.flags source · line 642 · raw
@+f:U32 -> @b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&1, 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes>
def gz.magic source · line 645 · raw
@ok:Bool -> @+f:U32 -> @b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&1, 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes>
def gz.head source · line 653 · raw
@r:Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, Maybe<&2, U32>) -> Maybe<&1, 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes>
ID1 31, ID2 139, CM 8 (DEFLATE), then FLG.
def gunzip source · line 663 · raw
@b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&1, 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes>
One gzip member; the CRC-32 and ISIZE must match. None: malformed, cut short, or corrupt. ponytail: bytes after the first member are ignored; loop over members if a server concatenates them.
def zl.sum source · line 667 · raw
@r:Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, U32) -> @c:Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, Maybe<&2, U32>) -> Maybe<&1, 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes>
RFC 1950: CMF and FLG, then DEFLATE, then Adler-32, big-endian.
def zl.trail source · line 672 · raw
@m:Maybe<&1, Inflated> -> Maybe<&1, 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes>
def zl.ok source · line 679 · raw
@+cmf:U32 -> @+flg:U32 -> Bool
def zl.go source · line 682 · raw
@ok:Bool -> @b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&1, 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes>
def zl.head source · line 689 · raw
@r:Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, Maybe<&2, U32>) -> Maybe<&1, 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes>
def unzlib source · line 697 · raw
@b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&1, 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes>
def bw.code source · line 703 · raw
@w:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Writer -> @cl:Pair(U32, U32) -> 0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Writer
def fx.hi source · line 708 · raw
@+s:U32 -> @lo:Bool -> Pair(U32, U32)
RFC 1951 §3.2.6: the fixed code of literal/length symbol s, and its length.
def fx.mid source · line 715 · raw
@+s:U32 -> @lo:Bool -> Pair(U32, U32)
def fx.low source · line 722 · raw
@+s:U32 -> @lo:Bool -> Pair(U32, U32)
def fx.lit source · line 729 · raw
@+s:U32 -> Pair(U32, U32)
def cx.go source · line 736 · raw
@bs:List<&2, U32> -> @es:List<&2, U32> -> @+v:U32 -> @+i:U32 -> @+best:Cx -> Cx
def em.len source · line 748 · raw
@w:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Writer -> @+len:U32 -> @c:Cx -> 0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Writer
def em.dist source · line 752 · raw
@w:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Writer -> @+d:U32 -> @c:Cx -> 0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Writer
def em.match source · line 756 · raw
@w:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Writer -> @+len:U32 -> @+d:U32 -> 0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Writer
def em.lit source · line 759 · raw
@w:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Writer -> @+c:U32 -> 0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Writer
def lz.at.of source · line 766 · raw
@r:Pair(Array<U32>, U32) -> @head:Array<U32> -> @prev:Array<U32> -> Pair(Lz, U32)
def lz.at source · line 770 · raw
@z:Lz -> @+i:U32 -> Pair(Lz, U32)
def lz.drop source · line 774 · raw
@r:Pair(Lz, U32) -> Lz
def lz.h3 source · line 778 · raw
@r:Pair(Lz, U32) -> @+a:U32 -> @+b:U32 -> Pair(Lz, U32)
def lz.h2 source · line 782 · raw
@r:Pair(Lz, U32) -> @+i:U32 -> @+a:U32 -> Pair(Lz, U32)
def lz.h1 source · line 786 · raw
@r:Pair(Lz, U32) -> @+i:U32 -> Pair(Lz, U32)
def lz.hash source · line 790 · raw
@z:Lz -> @+i:U32 -> Pair(Lz, U32)
def lz.link source · line 793 · raw
@r:Pair(Array<U32>, U32) -> @+i:U32 -> @+h:U32 -> @src:Array<U32> -> @prev:Array<U32> -> Pair(Lz, U32)
def lz.ins.of source · line 797 · raw
@r:Pair(Lz, U32) -> @+i:U32 -> Pair(Lz, U32)
def lz.insert source · line 803 · raw
@z:Lz -> @+i:U32 -> Pair(Lz, U32)
Links position i into the chain for its next three bytes; answers the chain's previous head.
def ml.cmp source · line 810 · raw
@r:Pair(Lz, U32) -> @+a:U32 -> @+b:U32 -> @+k:U32 -> @+x:U32 -> Ml
def ml.read source · line 814 · raw
@r:Pair(Lz, U32) -> @+a:U32 -> @+b:U32 -> @+k:U32 -> Ml
def ml.len source · line 818 · raw
@+k:U32 -> @eq:Bool -> U32
def ml.go source · line 826 · raw
@fuel:Nat -> @st:Ml -> Pair(Lz, U32)
Counts equal bytes from a and from b, up to fuel.
def ch.ok source · line 844 · raw
@+i:U32 -> @+c:U32 -> @+max:U32 -> @+blen:U32 -> Bool
RFC 1951 §3.2.5: a distance is at most 32768.
def ch.next source · line 847 · raw
@r:Pair(Array<U32>, U32) -> @src:Array<U32> -> @head:Array<U32> -> @+i:U32 -> @+max:U32 -> @+blen:U32 -> @+bdist:U32 -> Ch
def ch.best source · line 851 · raw
@r:Pair(Lz, U32) -> @+i:U32 -> @+p:U32 -> @+max:U32 -> @+blen:U32 -> @+bdist:U32 -> Ch
def ch.go source · line 857 · raw
@fuel:Nat -> @st:Ch -> Ch
def es.lit.of source · line 874 · raw
@r:Pair(Lz, U32) -> @w:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Writer -> @+i:U32 -> @+n:U32 -> Es
def es.lit source · line 879 · raw
@z:Lz -> @w:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Writer -> @+i:U32 -> @+n:U32 -> Es
def ins.one source · line 882 · raw
@ok:Bool -> @z:Lz -> @+j:U32 -> Lz
def ins.go source · line 890 · raw
@k:Nat -> @z:Lz -> @+j:U32 -> @+n:U32 -> Lz
Positions inside a match join their chains too, when three bytes remain.
def es.emit source · line 897 · raw
@hit:Bool -> @z:Lz -> @w:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Writer -> @+i:U32 -> @+n:U32 -> @+blen:U32 -> @+bdist:U32 -> Es
def es.pick source · line 905 · raw
@st:Ch -> @w:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Writer -> @+n:U32 -> Es
def es.chain source · line 910 · raw
@r:Pair(Lz, U32) -> @w:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Writer -> @+i:U32 -> @+n:U32 -> Es
ponytail: greedy parse, 32 chain steps; lazy matching would compress text further.
def es.find source · line 916 · raw
@short:Bool -> @z:Lz -> @w:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Writer -> @+i:U32 -> @+n:U32 -> Es
def es.go source · line 924 · raw
@fuel:Nat -> @st:Es -> Es
Each step consumes at least one byte, so n steps finish.
def es.out source · line 936 · raw
@st:Es -> 0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Writer
def deflate.into source · line 941 · raw
@w:0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Writer -> @b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> 0xa5b0f53eaf9c9d7c9694e326ca453a91/bits.Writer
One final fixed-Huffman block (BFINAL = 1, BTYPE = 01) after what w holds, padded to a byte.
def deflate source · line 946 · raw
@b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes
Raw DEFLATE.
def gz.put source · line 949 · raw
@r:Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, U32) -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes
def gzip source · line 956 · raw
@b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes
One gzip member (RFC 1952): no flags, mtime 0, OS unknown.
def zl.put source · line 959 · raw
@r:Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, U32) -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes
def zlib source · line 964 · raw
@b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes
RFC 1950: CMF 0x78 (32 KiB window), FLG 0x01 (fastest), then DEFLATE, then Adler-32, big-endian.
def words.got source · line 994 · raw
@r:Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)> -> Result<&1, &1, Pair(U32, String), 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes>
def libz.inflate source · line 1009 · raw
@max:U32 -> @b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> IO(Result<&1, &1, Pair(U32, String), 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes>)
gzip, zlib, or raw DEFLATE data through libz, selected from the first two bytes. Every gzip member is decoded in turn, as gzip -d does. Each decoder fails with EFBIG when the output passes max bytes, and ENOENT without its library.
def libz.inflate.raw source · line 1013 · raw
@max:U32 -> @b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> IO(Result<&1, &1, Pair(U32, String), 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes>)
One raw DEFLATE stream through libz. Trailing bytes, truncated input and output above max fail.
def libz.gzip source · line 1017 · raw
@b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> IO(Result<&1, &1, Pair(U32, String), 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes>)
One gzip member at level 6 through libz.
def zstd source · line 1024 · raw
@max:U32 -> @b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> IO(Result<&1, &1, Pair(U32, String), 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes>)
Zstandard frames (RFC 8878) through libzstd.
def brotli source · line 1028 · raw
@max:U32 -> @b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> IO(Result<&1, &1, Pair(U32, String), 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes>)
Brotli (RFC 7932) through libbrotlidec.
def dec.new.got source · line 1039 · raw
@r:Result<&1, &1, Pair(U32, String), U32> -> Result<&1, &1, Pair(U32, String), Decoder>
def dec.new source · line 1046 · raw
@+kind:U32 -> IO(Result<&1, &1, Pair(U32, String), Decoder>)
def inflate.new source · line 1051 · raw
IO(Result<&1, &1, Pair(U32, String), Decoder>)
def brotli.new source · line 1054 · raw
IO(Result<&1, &1, Pair(U32, String), Decoder>)
def zstd.new source · line 1057 · raw
IO(Result<&1, &1, Pair(U32, String), Decoder>)
def dec.push source · line 1066 · raw
@d:Decoder -> @max:U32 -> @b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> IO(Pair(Decoder, Result<&1, &1, Pair(U32, String), 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes>))
The output of one chunk of input. max caps this call, not the total output of the stream.
def dec.finish source · line 1079 · raw
@d:Decoder -> IO(Result<&1, &1, Pair(U32, String), Unit>)
Finish validates the end marker and always releases the decoder.
Templates
template words.run source · line 1001 · raw
@-eff:(@_:U32 -> @_:U32 -> @_:Array<U32> -> IO(Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)>)) -> @max:U32 -> @b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> IO(Result<&1, &1, Pair(U32, String), 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes>)
Effects (foreign code)
effect zstd.words source · line 969 · raw
@max:U32 -> @len:U32 -> @words:Array<U32> -> IO(Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)>)
The C libraries, through packed words at the effect boundary. Call the Bytes wrappers below.
foreign: effs/zlib.c, effs/zlib.js
effect inflate.words source · line 974 · raw
@max:U32 -> @len:U32 -> @words:Array<U32> -> IO(Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)>)
foreign: effs/zlib.c, effs/zlib.js
effect inflate.raw.words source · line 979 · raw
@max:U32 -> @len:U32 -> @words:Array<U32> -> IO(Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)>)
foreign: effs/zlib.c, effs/zlib.js
effect gzip.words source · line 984 · raw
@len:U32 -> @words:Array<U32> -> IO(Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)>)
foreign: effs/zlib.c, effs/zlib.js
effect brotli.words source · line 989 · raw
@max:U32 -> @len:U32 -> @words:Array<U32> -> IO(Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)>)
foreign: effs/zlib.c, effs/zlib.js
effect dec.open source · line 1035 · raw
@kind:U32 -> IO(Result<&1, &1, Pair(U32, String), U32>)
foreign: effs/zlib.c, effs/zlib.js
effect dec.feed source · line 1060 · raw
@id:U32 -> @max:U32 -> @len:U32 -> @words:Array<U32> -> IO(Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)>)
foreign: effs/zlib.c, effs/zlib.js
effect dec.finish.id source · line 1074 · raw
@id:U32 -> IO(Result<&1, &1, Pair(U32, String), Unit>)
foreign: effs/zlib.c, effs/zlib.js