Archive module

ZipFile

ZIP archive reader and writer.

ZipFile

#include <icy/archo/zipfile.h>

ZIP archive reader and writer.

Public Attributes

ReturnNameDescription
std::vector< FileInfo >info
unzFilefp

info

std::vector< FileInfo > info

fp

unzFile fp

Public Methods

ReturnNameDescription
ZipFileConstructs an unopened ZipFile. Call open() before use.
ZipFile explicitConstructs a ZipFile and immediately opens the archive at file.
~ZipFileCloses the archive if still open.
ZipFileDeleted constructor.
ZipFileDeleted constructor.
voidopenOpens the archive at file, closing any previously opened archive. Populates the info vector with metadata for every entry.
boolopened constReturns true if the archive is currently open.
voidcloseCloses the archive and releases the underlying file handle.
voidextractExtracts the archive contents to the given directory path.
boolextractCurrentFileExtracts the current file entry to path. Validates each entry against path-traversal attacks before writing.
boolgoToFirstFileMoves the internal cursor to the first file entry in the archive.
boolgoToNextFileAdvances the internal cursor to the next file entry.
voidopenCurrentFileOpens the current file entry for reading.
voidcloseCurrentFileCloses the current file entry.
std::stringcurrentFileNameReturns the name (relative path) of the current file entry.

ZipFile

ZipFile()

Constructs an unopened ZipFile. Call open() before use.


ZipFile

explicit

explicit ZipFile(const std::filesystem::path & file)

Constructs a ZipFile and immediately opens the archive at file.

Parameters

  • file Path to the ZIP archive to open.

~ZipFile

~ZipFile()

Closes the archive if still open.


ZipFile

ZipFile(const ZipFile &) = delete

Deleted constructor.


ZipFile

ZipFile(ZipFile &&) = delete

Deleted constructor.


open

void open(const std::filesystem::path & file)

Opens the archive at file, closing any previously opened archive. Populates the info vector with metadata for every entry.

Parameters

  • file Path to the ZIP archive.

Exceptions

  • std::runtime_error if the file cannot be opened.

opened

const

bool opened() const

Returns true if the archive is currently open.


close

void close()

Closes the archive and releases the underlying file handle.


extract

void extract(const std::filesystem::path & path)

Extracts the archive contents to the given directory path.

Parameters

  • path Destination directory; created automatically if necessary.

Exceptions

  • std::runtime_error if the archive is not open or a read error occurs.

extractCurrentFile

bool extractCurrentFile(const std::filesystem::path & path, bool whiny)

Extracts the current file entry to path. Validates each entry against path-traversal attacks before writing.

Parameters

  • path Destination base directory.

  • whiny If true, re-throws on error; otherwise returns false.

Returns

true on success, false if whiny is false and an error occurred.


goToFirstFile

bool goToFirstFile()

Moves the internal cursor to the first file entry in the archive.

Returns

true on success, false if the archive is empty or an error occurred.


goToNextFile

bool goToNextFile()

Advances the internal cursor to the next file entry.

Returns

true if another entry exists, false at end-of-list.


openCurrentFile

void openCurrentFile()

Opens the current file entry for reading.

Exceptions

  • std::runtime_error on failure.

closeCurrentFile

void closeCurrentFile()

Closes the current file entry.

Exceptions

  • std::runtime_error on failure.

currentFileName

std::string currentFileName()

Returns the name (relative path) of the current file entry.

Returns

Entry name as reported by the ZIP directory.