> For the complete documentation index, see [llms.txt](https://quantumphp.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://quantumphp.gitbook.io/docs/packages/archive/overview.md).

# Overview

Archive gives Quantum a small wrapper for building and extracting `.phar` and `.zip` files.

Use it when you want one package-level API for simple archive tasks such as bundling files for download, packaging generated exports, or unpacking an archive into a target directory.

## What it provides

* `ArchiveFactory` for resolving a PHAR or ZIP archive wrapper
* `Archive` as the package-level entry point
* two built-in adapters: `phar` and `zip`
* file add, string add, extract, count, and delete operations

## Quick example

```php
use Quantum\Archive\Factories\ArchiveFactory;
use Quantum\Archive\Enums\ArchiveType;

$archive = ArchiveFactory::get(ArchiveType::ZIP);
$archive->setName(storage_dir() . '/exports/reports.zip');

$archive->addFile(storage_dir() . '/reports/january.csv', 'january.csv');
$archive->addFromString('meta.txt', 'Generated by Quantum');
$archive->extractTo(storage_dir() . '/tmp/reports');
```

## Before you use it

Call `setName()` before any archive operation. Both adapters fail fast when the archive path was not set.

`ArchiveFactory::get()` reuses one `Archive` instance per adapter type through DI-backed caching. If you ask for `ArchiveType::ZIP` twice, you get the same wrapper object back.

That means archive name and adapter state are shared for that type inside the current process.

## Adapter choices

* `phar` is the default when you call `ArchiveFactory::get()` with no type
* `zip` uses PHP's `ZipArchive`
* unsupported adapter names throw immediately during factory resolution

## Operational constraints

* source files passed to `addFile()` must already exist or the package throws
* extraction returns `bool`, so failed extracts are not always raised as exceptions
* some adapter-specific behavior differs, especially around partial extraction and archive cleanup


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://quantumphp.gitbook.io/docs/packages/archive/overview.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
