|
Lightweight 0.20251202.0
|
#include <ZipArchive.hpp>
Public Member Functions | |
| ZipArchive (ZipArchive const &)=delete | |
| ZipArchive & | operator= (ZipArchive const &)=delete |
| ZipArchive (ZipArchive &&other) noexcept | |
| Move constructor. Transfers ownership of the archive handle. | |
| ZipArchive & | operator= (ZipArchive &&other) noexcept |
| Move assignment operator. Transfers ownership of the archive handle. | |
| ~ZipArchive () noexcept | |
| Destructor. Discards the archive if not explicitly closed. | |
| bool | IsOpen () const noexcept |
| zip_int64_t | EntryCount () const noexcept |
| zip_t * | NativeHandle () const noexcept |
| std::optional< zip_int64_t > | LocateEntry (std::string_view name) const |
| std::expected< EntryInfo, ZipError > | GetEntryInfo (zip_int64_t index) const |
| std::expected< ZipEntry, ZipError > | OpenEntry (zip_int64_t index) const |
| std::expected< std::vector< uint8_t >, ZipError > | ReadEntry (zip_int64_t index) const |
| std::expected< std::string, ZipError > | ReadEntryAsString (zip_int64_t index) const |
| std::expected< zip_int64_t, ZipError > | AddBuffer (std::string_view name, std::span< uint8_t const > data, CompressionMethod method=CompressionMethod::Deflate, uint32_t level=6) |
| std::expected< zip_int64_t, ZipError > | AddString (std::string_view name, std::string_view content, CompressionMethod method=CompressionMethod::Deflate, uint32_t level=6) |
| void | ForEachEntry (std::function< bool(zip_int64_t, std::string_view, zip_uint64_t)> const &callback) const |
| std::vector< EntryInfo > | GetAllEntries () const |
| std::expected< void, ZipError > | Close () |
| void | Discard () noexcept |
Static Public Member Functions | |
| static std::expected< ZipArchive, ZipError > | Open (std::filesystem::path const &path) |
| static std::expected< ZipArchive, ZipError > | Create (std::filesystem::path const &path) |
| static std::expected< ZipArchive, ZipError > | CreateOrTruncate (std::filesystem::path const &path) |
RAII wrapper for a ZIP archive (zip_t*).
This class provides safe, scoped access to a ZIP archive file. The archive is automatically closed when the ZipArchive object is destroyed.
ZipArchive objects are non-copyable but movable.
Definition at line 85 of file ZipArchive.hpp.
|
static |
Opens an existing ZIP archive for reading.
| path | The path to the archive file. |
|
static |
Creates a new ZIP archive.
| path | The path for the new archive file. |
|
static |
Creates a new ZIP archive, truncating any existing file.
| path | The path for the archive file. |
|
noexcept |
Checks if the archive is currently open.
|
noexcept |
Returns the number of entries in the archive.
|
noexcept |
Returns the native libzip handle.
| std::optional< zip_int64_t > Lightweight::Zip::ZipArchive::LocateEntry | ( | std::string_view | name | ) | const |
Locates an entry by name.
| name | The name of the entry to find. |
| std::expected< EntryInfo, ZipError > Lightweight::Zip::ZipArchive::GetEntryInfo | ( | zip_int64_t | index | ) | const |
Gets information about an entry by index.
| index | The entry index. |
| std::expected< std::vector< uint8_t >, ZipError > Lightweight::Zip::ZipArchive::ReadEntry | ( | zip_int64_t | index | ) | const |
Reads an entire entry as binary data.
| index | The entry index. |
| std::expected< std::string, ZipError > Lightweight::Zip::ZipArchive::ReadEntryAsString | ( | zip_int64_t | index | ) | const |
Reads an entire entry as a string.
| index | The entry index. |
| std::expected< zip_int64_t, ZipError > Lightweight::Zip::ZipArchive::AddBuffer | ( | std::string_view | name, |
| std::span< uint8_t const > | data, | ||
| CompressionMethod | method = CompressionMethod::Deflate, |
||
| uint32_t | level = 6 |
||
| ) |
Adds binary data as a new entry.
| name | The name for the new entry. |
| data | The binary data to add. |
| method | The compression method to use. |
| level | The compression level (0-9, where 0 is no compression). |
| std::expected< zip_int64_t, ZipError > Lightweight::Zip::ZipArchive::AddString | ( | std::string_view | name, |
| std::string_view | content, | ||
| CompressionMethod | method = CompressionMethod::Deflate, |
||
| uint32_t | level = 6 |
||
| ) |
Adds string content as a new entry.
| name | The name for the new entry. |
| content | The string content to add. |
| method | The compression method to use. |
| level | The compression level (0-9, where 0 is no compression). |
| void Lightweight::Zip::ZipArchive::ForEachEntry | ( | std::function< bool(zip_int64_t, std::string_view, zip_uint64_t)> const & | callback | ) | const |
Iterates over all entries in the archive.
| callback | Function called for each entry. Return false to stop iteration. Parameters: (index, name, uncompressed_size) |
| std::vector< EntryInfo > Lightweight::Zip::ZipArchive::GetAllEntries | ( | ) | const |
Gets information about all entries in the archive.
| std::expected< void, ZipError > Lightweight::Zip::ZipArchive::Close | ( | ) |
Closes the archive, writing all changes to disk.
|
noexcept |
Discards the archive without writing changes.
Use this to abandon modifications without saving them.