gzip.bend checks
raw source on the hub · import element-compress@0.1.0.0/gzip.bend as Gzip
3 imports
import Base import ./inflate.bend as Inflate import ./checksum.bend as Ck
Types
type Enc source · line 192 · raw
Data
A Content-Encoding as a constructor, so decode matches on it and only
the decoder named runs (Bool.pick builds every arm: an identity body
would be tried as gzip and as deflate, a gzip one as raw deflate too).
IdentityEnc
GzEnc
DeflEnc
Other@name:String -> Enc
Definitions
def le16 source · line 15 · raw
@xs:List<&2, U32> -> U32
def le32 source · line 26 · raw
@+xs:List<&2, U32> -> U32
def be32 source · line 31 · raw
@xs:List<&2, U32> -> U32
def after_zero source · line 51 · raw
@xs:List<&2, U32> -> List<&2, U32>
the bytes after a zero byte (a zero-terminated name or comment)
def drop_if source · line 60 · raw
@c:Bool -> @xs:List<&2, U32> -> @+n:Nat -> List<&2, U32>
def skip_zero_if source · line 67 · raw
@c:Bool -> @xs:List<&2, U32> -> List<&2, U32>
def byte_at source · line 74 · raw
@+xs:List<&2, U32> -> @+i:Nat -> U32
def low8 source · line 77 · raw
@+v:U32 -> U32
def gzip_body source · line 85 · raw
@+xs:List<&2, U32> -> Result<&2, &2, String, List<&2, U32>>
The header: ID1 ID2 CM FLG MTIME(4) XFL OS, then FEXTRA (a 2-byte length and that many bytes), FNAME and FCOMMENT (zero-terminated), FHCRC (2 bytes), as FLG says. Answers the DEFLATE stream and what follows, or "".
def gzip_trailer source · line 104 · raw
@o:0xb695b6828d1566fc34b3704144f8ed1f/inflate.Out -> Result<&2, &2, String, List<&2, U32>>
the trailer: CRC-32 and the size mod 2^32 of the bytes, little-endian
def gzip_inflated source · line 115 · raw
@r:Result<&2, &2, String, 0xb695b6828d1566fc34b3704144f8ed1f/inflate.Out> -> Result<&2, &2, String, List<&2, U32>>
def gzip_stream source · line 122 · raw
@r:Result<&2, &2, String, List<&2, U32>> -> Result<&2, &2, String, List<&2, U32>>
def gunzip source · line 130 · raw
@+xs:List<&2, U32> -> Result<&2, &2, String, List<&2, U32>>
the bytes a gzip member holds (one member; a second is left unread)
def zlib_trailer source · line 135 · raw
@o:0xb695b6828d1566fc34b3704144f8ed1f/inflate.Out -> Result<&2, &2, String, List<&2, U32>>
def zlib_inflated source · line 142 · raw
@r:Result<&2, &2, String, 0xb695b6828d1566fc34b3704144f8ed1f/inflate.Out> -> Result<&2, &2, String, List<&2, U32>>
def zlib_ok source · line 151 · raw
@+xs:List<&2, U32> -> Bool
CMF (CM 8, CINFO <= 7) and FLG with (CMF * 256 + FLG) a multiple of 31; a preset dictionary (FDICT) is refused
def zlib_dict source · line 156 · raw
@+xs:List<&2, U32> -> Bool
def zlib_checked source · line 161 · raw
@ok:Bool -> @dict:Bool -> @+xs:List<&2, U32> -> Result<&2, &2, String, List<&2, U32>>
(a match on the checks: Bool.pick builds both arms, so the inflate
would run on a stream the header already refused)
def unzlib source · line 172 · raw
@+xs:List<&2, U32> -> Result<&2, &2, String, List<&2, U32>>
def deflate_as source · line 179 · raw
@zlib:Bool -> @+xs:List<&2, U32> -> Result<&2, &2, String, List<&2, U32>>
"deflate" is a zlib stream by the RFCs, a raw one from some servers: the
header decides (a match: a pick would inflate the stream both ways)
def deflate_body source · line 186 · raw
@+xs:List<&2, U32> -> Result<&2, &2, String, List<&2, U32>>
def enc_of source · line 198 · raw
@+enc:String -> Enc
def decode_as source · line 203 · raw
@e:Enc -> @xs:List<&2, U32> -> Result<&2, &2, String, List<&2, U32>>
def decode source · line 216 · raw
@+enc:String -> @xs:List<&2, U32> -> Result<&2, &2, String, List<&2, U32>>
The body a Content-Encoding names decoded: gzip, x-gzip, deflate; "" or identity as is; anything else (br, zstd, compress) is refused.