Archive module

ZipFile

ZIP archive reader and writer.

#include <icy/archo/zipfile.h>

struct ZipFile

Defined in src/archo/include/icy/archo/zipfile.h:36

Public Attributes

ReturnNameDescription
std::vector< FileInfo >info
unzFilefp
uint64_t_totalWritten
uint64_t_entriesExtracted

info

std::vector< FileInfo > info

Type: std::vector< FileInfo >

Defined in src/archo/include/icy/archo/zipfile.h:105


fp

unzFile fp

Defined in src/archo/include/icy/archo/zipfile.h:106


_totalWritten

uint64_t _totalWritten = 0

Defined in src/archo/include/icy/archo/zipfile.h:107


_entriesExtracted

uint64_t _entriesExtracted = 0

Defined in src/archo/include/icy/archo/zipfile.h:108

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.
ZipFile &operator=Deleted assignment operator.
ZipFileDeleted constructor.
ZipFile &operator=Deleted assignment operator.
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()

Defined in src/archo/include/icy/archo/zipfile.h:39

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


ZipFile

explicit

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

Defined in src/archo/include/icy/archo/zipfile.h:43

Constructs a ZipFile and immediately opens the archive at file.

Parameters

ParameterTypeDescription
fileconst std::filesystem::path &Path to the ZIP archive to open.

~ZipFile

~ZipFile()

Defined in src/archo/include/icy/archo/zipfile.h:46

Closes the archive if still open.


ZipFile

ZipFile(const ZipFile &) = delete

Defined in src/archo/include/icy/archo/zipfile.h:48

Deleted constructor.


operator=

ZipFile & operator=(const ZipFile &) = delete

Defined in src/archo/include/icy/archo/zipfile.h:49

Deleted assignment operator.


ZipFile

ZipFile(ZipFile &&) = delete

Defined in src/archo/include/icy/archo/zipfile.h:50

Deleted constructor.


operator=

ZipFile & operator=(ZipFile &&) = delete

Defined in src/archo/include/icy/archo/zipfile.h:51

Deleted assignment operator.


open

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

Defined in src/archo/include/icy/archo/zipfile.h:57

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

Parameters

ParameterTypeDescription
fileconst std::filesystem::path &Path to the ZIP archive.

Exceptions

ExceptionDescription
std::runtime_errorif the file cannot be opened.

opened

const

bool opened() const

Defined in src/archo/include/icy/archo/zipfile.h:60

Returns true if the archive is currently open.


close

void close()

Defined in src/archo/include/icy/archo/zipfile.h:63

Closes the archive and releases the underlying file handle.


extract

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

Defined in src/archo/include/icy/archo/zipfile.h:68

Extracts the archive contents to the given directory path.

Parameters

ParameterTypeDescription
pathconst std::filesystem::path &Destination directory; created automatically if necessary.

Exceptions

ExceptionDescription
std::runtime_errorif the archive is not open or a read error occurs.

extractCurrentFile

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

Defined in src/archo/include/icy/archo/zipfile.h:75

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

Returns

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

Parameters

ParameterTypeDescription
pathconst std::filesystem::path &Destination base directory.
whinyboolIf true, re-throws on error; otherwise returns false.

goToFirstFile

bool goToFirstFile()

Defined in src/archo/include/icy/archo/zipfile.h:79

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()

Defined in src/archo/include/icy/archo/zipfile.h:83

Advances the internal cursor to the next file entry.

Returns

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


openCurrentFile

void openCurrentFile()

Defined in src/archo/include/icy/archo/zipfile.h:87

Opens the current file entry for reading.

Exceptions

ExceptionDescription
std::runtime_erroron failure.

closeCurrentFile

void closeCurrentFile()

Defined in src/archo/include/icy/archo/zipfile.h:91

Closes the current file entry.

Exceptions

ExceptionDescription
std::runtime_erroron failure.

currentFileName

std::string currentFileName()

Defined in src/archo/include/icy/archo/zipfile.h:95

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

Returns

Entry name as reported by the ZIP directory.