packkit/gzip
The gzip header: the original file name, a comment, the modification
time and extra subfields. Use packkit.compress and
packkit.decompress when you do not need them.
Types
The optional fields of a gzip member header (RFC 1952).
pub type Header {
Header(
name: option.Option(String),
comment: option.Option(String),
modified_at: option.Option(Int),
extra: List(Subfield),
)
}
Constructors
-
Header( name: option.Option(String), comment: option.Option(String), modified_at: option.Option(Int), extra: List(Subfield), )Arguments
- name
-
Original file name.
- modified_at
-
Modification time in Unix seconds. gzip stores “no time stamp” as 0, so both
NoneandSome(0)are written as 0 and read back asNone. - extra
-
Extra subfields, written in order.
Why encode could not write a header.
pub type HeaderError {
NameContainsNul
CommentContainsNul
ModifiedAtOutOfRange(value: Int)
SubfieldIdOutOfRange(id_1: Int, id_2: Int)
SubfieldTooLong(length: Int)
ExtraTooLong(length: Int)
}
Constructors
-
NameContainsNul -
CommentContainsNul -
ModifiedAtOutOfRange(value: Int)The modification time does not fit in 32 bits.
-
SubfieldIdOutOfRange(id_1: Int, id_2: Int)A subfield id byte is outside 0 to 255.
-
SubfieldTooLong(length: Int)A subfield body is longer than 65,535 bytes.
-
ExtraTooLong(length: Int)All subfields together are longer than 65,535 bytes.
Values
pub fn decode(
bytes: BitArray,
limits limits: limit.Limits,
) -> Result(Decoded, codec.CodecError)
Decompresses a gzip stream and returns the header with the payload.
Use packkit.decompress when you only need the payload.
A stream of several members, such as the output of cat a.gz b.gz,
returns the header of the first member and the payloads of all
members joined. Returns InvalidData when a header, CRC-32 or size
check fails.
pub fn encode(
bytes: BitArray,
header header: Header,
) -> Result(BitArray, HeaderError)
Compresses bytes into a gzip stream with header.
Examples
let header =
Header(name: Some("report.csv"), comment: None, modified_at: None, extra: [])
let assert Ok(bytes) = encode(<<"a,b\n":utf8>>, header:)
decode(bytes, limits: limit.default())
// -> Ok(Decoded(header:, payload: <<"a,b\n":utf8>>))
encode(<<>>, header: Header(..header, name: Some("a\u{0000}b")))
// -> Error(NameContainsNul)