interplane.Get Omega
Read in your language

omega-zip

omega-zip: ZIP archive reader in seeded Omega (store and deflate, CRC-32, fail-closed refusals)

Brought by drakestapleton

branch main Branches Tags History

omega-zip / src / zlibd.om

47 lines · 1071 bytes Raw Blame History
1note ======== src/zlibd.om: the zlib wrapper (RFC 1950) and the raw DEFLATE tool ========
2note Header: CMF (CM = 8 deflate, CINFO <= 7, a window of at most 32 KiB) and FLG with
3note (CMF * 256 + FLG) a multiple of 31 (RFC 1950 section 2.2). FDICT (a preset dictionary) is
4note refused: this decoder has no way to be given one. After the last block the stream is
5note byte-aligned and the Adler-32 of the output follows, most significant byte first (section 2.2,
6note 8.2). Bytes after the trailer are not read.
7
8text tzhdr "bad zlib header"
9text tzdict "preset dictionary is not supported"
10text tzsum "Adler-32 check failed"
11
12fn rawrun to int
13insrc 0 0 0 0
14osink 1 OUTMAX 0 0
15inflate
16ret 0
17end
18
19fn zlibrun to int
20insrc 0 0 0 0
21osink 1 OUTMAX 0 2
22a = inbyte
23b = inbyte
24if ne and a 15 8
25fail 30 tzhdr
26end
27if gt shr a 4 7
28fail 30 tzhdr
29end
30if ne rem or shl a 8 b 31 0
31fail 30 tzhdr
32end
33if ne and b 32 0
34fail 31 tzdict
35end
36inflate
37put bitb 0 0
38put bitn 0 0
39s = ulong 0
40for i ulong 4
41s = or shl s 8 inbyte
42end
43if ne s or shl get adb 0 16 get ada 0
44fail 32 tzsum
45end
46ret 0
47end