# ZipFile

<a id="zipfile"></a>

# ZipFile

```cpp
#include <icy/archo/zipfile.h>

struct ZipFile
```

[Defined in src/archo/include/icy/archo/zipfile.h:36](https://github.com/auscaster/icey/blob/main/src/archo/include/icy/archo/zipfile.h#L36)

ZIP archive reader and writer.

## Public Attributes

| Return | Name | Description |
|--------|------|-------------|
| std::vector< [`FileInfo`](https://auscaster.com/icey/docs/api-reference/icy-archo-ZipFile-FileInfo.md#fileinfo) > | [`info`](#info-1)  |  |
| `unzFile` | [`fp`](#fp)  |  |
| `uint64_t` | [`_totalWritten`](#_totalwritten)  |  |
| `uint64_t` | [`_entriesExtracted`](#_entriesextracted)  |  |

---

<a id="info-1"></a>

### info

```cpp
std::vector< FileInfo > info
```

Type: std::vector< [`FileInfo`](https://auscaster.com/icey/docs/api-reference/icy-archo-ZipFile-FileInfo.md#fileinfo) >

[Defined in src/archo/include/icy/archo/zipfile.h:105](https://github.com/auscaster/icey/blob/main/src/archo/include/icy/archo/zipfile.h#L105)

---

<a id="fp"></a>

### fp

```cpp
unzFile fp
```

[Defined in src/archo/include/icy/archo/zipfile.h:106](https://github.com/auscaster/icey/blob/main/src/archo/include/icy/archo/zipfile.h#L106)

---

<a id="_totalwritten"></a>

### _totalWritten

```cpp
uint64_t _totalWritten = 0
```

[Defined in src/archo/include/icy/archo/zipfile.h:107](https://github.com/auscaster/icey/blob/main/src/archo/include/icy/archo/zipfile.h#L107)

---

<a id="_entriesextracted"></a>

### _entriesExtracted

```cpp
uint64_t _entriesExtracted = 0
```

[Defined in src/archo/include/icy/archo/zipfile.h:108](https://github.com/auscaster/icey/blob/main/src/archo/include/icy/archo/zipfile.h#L108)

## Public Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`ZipFile`](#zipfile-1)  | Constructs an unopened [ZipFile](#zipfile). Call [open()](#open-7) before use. |
|  | [`ZipFile`](#zipfile-2) `explicit` | Constructs a [ZipFile](#zipfile) and immediately opens the archive at `file`. |
|  | [`~ZipFile`](#zipfile-3)  | Closes the archive if still open. |
|  | [`ZipFile`](#zipfile-4)  | Deleted constructor. |
| [`ZipFile`](#zipfile) & | [`operator=`](#operator-234)  | Deleted assignment operator. |
|  | [`ZipFile`](#zipfile-5)  | Deleted constructor. |
| [`ZipFile`](#zipfile) & | [`operator=`](#operator-235)  | Deleted assignment operator. |
| `void` | [`open`](#open-7)  | Opens the archive at `file`, closing any previously opened archive. Populates the `info` vector with metadata for every entry. |
| `bool` | [`opened`](#opened) `const` | Returns true if the archive is currently open. |
| `void` | [`close`](#close-30)  | Closes the archive and releases the underlying file handle. |
| `void` | [`extract`](#extract)  | Extracts the archive contents to the given directory path. |
| `bool` | [`extractCurrentFile`](#extractcurrentfile)  | Extracts the current file entry to `path`. Validates each entry against path-traversal attacks before writing. |
| `bool` | [`goToFirstFile`](#gotofirstfile)  | Moves the internal cursor to the first file entry in the archive. |
| `bool` | [`goToNextFile`](#gotonextfile)  | Advances the internal cursor to the next file entry. |
| `void` | [`openCurrentFile`](#opencurrentfile)  | Opens the current file entry for reading. |
| `void` | [`closeCurrentFile`](#closecurrentfile)  | Closes the current file entry. |
| `std::string` | [`currentFileName`](#currentfilename)  | Returns the name (relative path) of the current file entry. |

---

<a id="zipfile-1"></a>

### ZipFile

```cpp
ZipFile()
```

[Defined in src/archo/include/icy/archo/zipfile.h:39](https://github.com/auscaster/icey/blob/main/src/archo/include/icy/archo/zipfile.h#L39)

Constructs an unopened [ZipFile](#zipfile). Call [open()](#open-7) before use.

---

<a id="zipfile-2"></a>

### ZipFile

`explicit`

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

[Defined in src/archo/include/icy/archo/zipfile.h:43](https://github.com/auscaster/icey/blob/main/src/archo/include/icy/archo/zipfile.h#L43)

Constructs a [ZipFile](#zipfile) and immediately opens the archive at `file`.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `file` | `const std::filesystem::path &` | Path to the ZIP archive to open. |

---

<a id="zipfile-3"></a>

### ~ZipFile

```cpp
~ZipFile()
```

[Defined in src/archo/include/icy/archo/zipfile.h:46](https://github.com/auscaster/icey/blob/main/src/archo/include/icy/archo/zipfile.h#L46)

Closes the archive if still open.

---

<a id="zipfile-4"></a>

### ZipFile

```cpp
ZipFile(const ZipFile &) = delete
```

[Defined in src/archo/include/icy/archo/zipfile.h:48](https://github.com/auscaster/icey/blob/main/src/archo/include/icy/archo/zipfile.h#L48)

Deleted constructor.

---

<a id="operator-234"></a>

### operator=

```cpp
ZipFile & operator=(const ZipFile &) = delete
```

[Defined in src/archo/include/icy/archo/zipfile.h:49](https://github.com/auscaster/icey/blob/main/src/archo/include/icy/archo/zipfile.h#L49)

Deleted assignment operator.

---

<a id="zipfile-5"></a>

### ZipFile

```cpp
ZipFile(ZipFile &&) = delete
```

[Defined in src/archo/include/icy/archo/zipfile.h:50](https://github.com/auscaster/icey/blob/main/src/archo/include/icy/archo/zipfile.h#L50)

Deleted constructor.

---

<a id="operator-235"></a>

### operator=

```cpp
ZipFile & operator=(ZipFile &&) = delete
```

[Defined in src/archo/include/icy/archo/zipfile.h:51](https://github.com/auscaster/icey/blob/main/src/archo/include/icy/archo/zipfile.h#L51)

Deleted assignment operator.

---

<a id="open-7"></a>

### open

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

[Defined in src/archo/include/icy/archo/zipfile.h:57](https://github.com/auscaster/icey/blob/main/src/archo/include/icy/archo/zipfile.h#L57)

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

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `file` | `const std::filesystem::path &` | Path to the ZIP archive. |

#### Exceptions

| Exception | Description |
|-----------|-------------|
| `std::runtime_error` | if the file cannot be opened. |

---

<a id="opened"></a>

### opened

`const`

```cpp
bool opened() const
```

[Defined in src/archo/include/icy/archo/zipfile.h:60](https://github.com/auscaster/icey/blob/main/src/archo/include/icy/archo/zipfile.h#L60)

Returns true if the archive is currently open.

---

<a id="close-30"></a>

### close

```cpp
void close()
```

[Defined in src/archo/include/icy/archo/zipfile.h:63](https://github.com/auscaster/icey/blob/main/src/archo/include/icy/archo/zipfile.h#L63)

Closes the archive and releases the underlying file handle.

---

<a id="extract"></a>

### extract

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

[Defined in src/archo/include/icy/archo/zipfile.h:68](https://github.com/auscaster/icey/blob/main/src/archo/include/icy/archo/zipfile.h#L68)

Extracts the archive contents to the given directory path.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `path` | `const std::filesystem::path &` | Destination directory; created automatically if necessary. |

#### Exceptions

| Exception | Description |
|-----------|-------------|
| `std::runtime_error` | if the archive is not open or a read error occurs. |

---

<a id="extractcurrentfile"></a>

### extractCurrentFile

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

[Defined in src/archo/include/icy/archo/zipfile.h:75](https://github.com/auscaster/icey/blob/main/src/archo/include/icy/archo/zipfile.h#L75)

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

| Parameter | Type | Description |
|-----------|------|-------------|
| `path` | `const std::filesystem::path &` | Destination base directory. |
| `whiny` | `bool` | If true, re-throws on error; otherwise returns false. |

---

<a id="gotofirstfile"></a>

### goToFirstFile

```cpp
bool goToFirstFile()
```

[Defined in src/archo/include/icy/archo/zipfile.h:79](https://github.com/auscaster/icey/blob/main/src/archo/include/icy/archo/zipfile.h#L79)

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.

---

<a id="gotonextfile"></a>

### goToNextFile

```cpp
bool goToNextFile()
```

[Defined in src/archo/include/icy/archo/zipfile.h:83](https://github.com/auscaster/icey/blob/main/src/archo/include/icy/archo/zipfile.h#L83)

Advances the internal cursor to the next file entry. 
#### Returns
true if another entry exists, false at end-of-list.

---

<a id="opencurrentfile"></a>

### openCurrentFile

```cpp
void openCurrentFile()
```

[Defined in src/archo/include/icy/archo/zipfile.h:87](https://github.com/auscaster/icey/blob/main/src/archo/include/icy/archo/zipfile.h#L87)

Opens the current file entry for reading.

#### Exceptions

| Exception | Description |
|-----------|-------------|
| `std::runtime_error` | on failure. |

---

<a id="closecurrentfile"></a>

### closeCurrentFile

```cpp
void closeCurrentFile()
```

[Defined in src/archo/include/icy/archo/zipfile.h:91](https://github.com/auscaster/icey/blob/main/src/archo/include/icy/archo/zipfile.h#L91)

Closes the current file entry.

#### Exceptions

| Exception | Description |
|-----------|-------------|
| `std::runtime_error` | on failure. |

---

<a id="currentfilename"></a>

### currentFileName

```cpp
std::string currentFileName()
```

[Defined in src/archo/include/icy/archo/zipfile.h:95](https://github.com/auscaster/icey/blob/main/src/archo/include/icy/archo/zipfile.h#L95)

Returns the name (relative path) of the current file entry. 
#### Returns
Entry name as reported by the ZIP directory.
