Jazz2::Utils::ZipArchive class

Reads a ZIP archive.

Supports stored and Deflate entries, names in UTF-8 or code page 437, and ZIP64. Only the central directory is read by Open(), the entries are decompressed on request and checked against their size and CRC-32, so a damaged or forged archive never produces more than it declares.

Public static functions

static auto GetErrorDescription(ZipError error) -> StringView
Returns a short description of an error for logs and messages.

Constructors, destructors, conversion operators

ZipArchive()

Public functions

auto Open(StringView path, std::uint32_t maxEntries = 65536) -> ZipError
Opens an archive and reads its directory.
auto GetEntries() const -> ArrayView<const ZipEntry>
Returns all entries of the archive.
auto Extract(const ZipEntry& entry, Stream& target, std::uint64_t maxSize = UINT64_MAX) const -> ZipError
Decompresses an entry into a stream.
auto ExtractToFile(const ZipEntry& entry, StringView targetPath, std::uint64_t maxSize = UINT64_MAX) const -> ZipError
Decompresses an entry into a file, the file is removed if it fails.

Function documentation

ZipError Jazz2::Utils::ZipArchive::Open(StringView path, std::uint32_t maxEntries = 65536)

Opens an archive and reads its directory.

Parameters
path Archive file
maxEntries Largest number of entries accepted

ZipError Jazz2::Utils::ZipArchive::Extract(const ZipEntry& entry, Stream& target, std::uint64_t maxSize = UINT64_MAX) const

Decompresses an entry into a stream.

Fails with ZipError::TooLarge if the entry is larger than maxSize, before anything is written.