Karta. Compression
(Karta v1.0.0)
Reading compressed data that came from outside Karta, within a bound: the gzip and zip archives that DMARC aggregate reports and TLS reports arrive in.
Every function takes the most bytes it may produce. A stream that would
produce more is refused ({:error, :too_large}) as soon as the limit is
passed, so a small archive cannot expand into a large one: the work and
the memory are those of the limit, not of what the archive declares.
gunzip/2 checks the gzip header and trailer: a stream cut short, whose
contents do not match its CRC or whose length is not what it says, is
refused ({:error, :invalid}). inflate/2 reads a raw deflate stream
for unzip/2; that stream's completeness is checked by the archive's own
CRC and size.
unzip/2 reads an archive of exactly one file, keeping it in memory. It
reads the archive's own directory rather than trusting a file name, and
the file's name is never used: nothing is written to disk, so no path in
an archive can reach the file system. A file whose contents do not match
its size or CRC is refused ({:error, :invalid}).
Summary
Functions
Inflates a gzip stream, producing at most limit bytes.
Inflates a raw deflate stream, producing at most limit bytes.
Reads the one file of a zip archive, producing at most limit bytes.
Functions
@spec gunzip(binary(), non_neg_integer()) :: {:ok, binary()} | {:error, :too_large | :invalid}
Inflates a gzip stream, producing at most limit bytes.
@spec inflate(binary(), non_neg_integer()) :: {:ok, binary()} | {:error, :too_large | :invalid}
Inflates a raw deflate stream, producing at most limit bytes.
@spec unzip(binary(), non_neg_integer()) :: {:ok, binary()} | {:error, :too_large | :invalid | :multiple_files | :encrypted | :unsupported}
Reads the one file of a zip archive, producing at most limit bytes.