std.gzip
gzip (RFC 1952), decompressed: members, one after another, each
DEFLATE data between a header and the CRC-32 and the length of what it
holds, as Go’s compress/gzip reads them — the bytes of all the
members, one after another. A header’s file name, comment and extra
field are passed over, and its own CRC, where it has one, checked.
Import it by a name, import std.gzip as Gzip.
import bytes as Bytesimport std.flate as Flateimport std.gzip as Gzip
-- | the text of a file that was gzipped, where it is gzipunzipped : Bytes -> Either Flate.CorruptInput Stringunzipped content = case Gzip.decompress content of Right out -> Right (show out) Left e -> Left edecompress
decompress : Bytes -> Either Flate.CorruptInput BytesThe gzip members of the bytes, decompressed, their bytes one after another, each checked by its CRC-32 and its length. The bytes must be members and nothing else, and at least one. Where they are wrong, the byte of the input where it went wrong, and what is wrong.
>>> decompress b[31, 139, 8, 0, 0, 0, 0, 0, 0, 3, 203, "H", 205, 201, 201, 7, 0, 134, 166, 16, "6", 5, 0, 0, 0]Right b["hello"]>>> decompress b[31, 139, 8, 0, 0, 0, 0, 0, 0, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0]Right b[](two members; a file name; an extra field, a name, a comment and the header’s CRC)
>>> decompress b[31, 139, 8, 0, 0, 0, 0, 0, 0, 3, 203, "H", 205, 201, 201, 215, "Q", 0, 0, 153, "V", 234, 17, 7, 0, 0, 0, 31, 139, 8, 0, 0, 0, 0, 0, 0, 3, "+", 207, "/", 202, "I", 1, 0, "C", 17, "w:", 5, 0, 0, 0]Right b["hello, world"]>>> decompress b[31, 139, 8, 9, 0, 0, 0, 0, 0, 3, "hi.txt", 0, 203, 200, 4, 0, 172, "*", 147, 216, 2, 0, 0, 0]Right b["hi"]>>> decompress b[31, 139, 8, 30, 0, 0, 0, 0, 0, 3, 2, 0, "abn", 0, "c", 0, 132, 139, 203, 200, 4, 0, 172, "*", 147, 216, 2, 0, 0, 0]Right b["hi"](a header’s CRC not its own; not gzip; another method than DEFLATE; a flag no one knows)
>>> decompress b[31, 139, 8, 10, 0, 0, 0, 0, 0, 3, "n", 0, "\"4", 203, 200, 4, 0, 172, "*", 147, 216, 2, 0, 0, 0]Left { offset = 12, message = "header crc mismatch" }>>> decompress b[31, 140, 8, 0, 0, 0, 0, 0, 0, 3, 203, 200, 4, 0, 172, "*", 147, 216, 2, 0, 0, 0]Left { offset = 0, message = "incorrect header check" }>>> decompress b[31, 139, 7, 0, 0, 0, 0, 0, 0, 3, 203, 200, 4, 0, 172, "*", 147, 216, 2, 0, 0, 0]Left { offset = 2, message = "unknown compression method" }>>> decompress b[31, 139, 8, " ", 0, 0, 0, 0, 0, 3, 203, 200, 4, 0, 172, "*", 147, 216, 2, 0, 0, 0]Left { offset = 3, message = "unknown header flags set" }(DEFLATE data that is wrong; a CRC-32 or a length not the data’s)
>>> decompress b[31, 139, 8, 0, 0, 0, 0, 0, 0, 3, 7]Left { offset = 10, message = "invalid block type 3" }>>> decompress b[31, 139, 8, 0, 0, 0, 0, 0, 0, 3, 203, 200, 4, 0, 173, "*", 147, 216, 2, 0, 0, 0]Left { offset = 14, message = "incorrect data check" }>>> decompress b[31, 139, 8, 0, 0, 0, 0, 0, 0, 3, 203, 200, 4, 0, 172, "*", 147, 216, 3, 0, 0, 0]Left { offset = 18, message = "incorrect length check" }(too few bytes: a trailer, a header, a name not ended, none at all; after a member, what is not one)
>>> decompress b[31, 139, 8, 0, 0, 0, 0, 0, 0, 3, 203, 200, 4, 0, 172, "*", 147, 216, 2]Left { offset = 19, message = "unexpected end of input" }>>> decompress b[31, 139, 8, 0, 0, 0]Left { offset = 6, message = "unexpected end of input" }>>> decompress b[31, 139, 8, 8, 0, 0, 0, 0, 0, 3, "abc"]Left { offset = 13, message = "unexpected end of input" }>>> decompress b[]Left { offset = 0, message = "unexpected end of input" }>>> decompress b[31, 139, 8, 0, 0, 0, 0, 0, 0, 3, 203, 200, 4, 0, 172, "*", 147, 216, 2, 0, 0, 0, "x"]Left { offset = 23, message = "unexpected end of input" }