# fs.archive.extract

Unpacks a tar.gz archive into a folder of a project store

# fs.archive.extract

```
fs.archive.extract --from ARCHIVE [--format tar.gz] [--delete-source] [--store TEXT] [--folder TEXT] [--on-conflict error|skip|overwrite] → archive
```

Unpacks a tar.gz archive into a folder of a project store. Open the tar.gz archive `--from` names — a FileRef, an upload or a store key — into `--folder` (default `extracted/<archive>`). A member that climbs out of the folder or is a link refuses the whole archive before anything is written. A folder that is not empty is an error unless `--on-conflict` says otherwise (`overwrite` replaces it). `--delete-source` removes the archive once every member is written. Adds `archive: { folder, items, count, source_deleted }` — `items` a durable FileRef per file — and keeps the rest of the payload.

## Flags

- `--from` (required): The archive: a FileRef, an upload or a store key.
- `--format`: The archive format: tar.gz (default, the only one).
- `--delete-source`: Delete the archive once every member is written.
- `--store`: The project store to write to: `local`, or the id of an `s3` credential. Saved explicitly when the pipeline is registered (default: the project's default store at that moment)
- `--folder`: The folder the archive opens into (default: extracted/<archive>).
- `--on-conflict`: When the target already exists: overwrite, skip or error (default: error)

## Examples

### Unpack an uploaded archive

```
| fs.archive.extract --from "{{ input.file }}" --folder imports/latest --delete-source
```

Input:

```json
{
  "file": {
    "__zf_type": "file_ref",
    "backend": "zebfs",
    "store": "local",
    "ref": "uploads/bundle.tar.gz",
    "filename": "bundle.tar.gz",
    "mime": "application/gzip",
    "kind": "archive",
    "size": 40211,
    "sha256": "sha256:…",
    "lifecycle": "durable",
    "origin": "fs.file.put",
    "trust": "untrusted"
  }
}
```

It answers:

```json
{
  "file": {
    "__zf_type": "file_ref",
    "backend": "zebfs",
    "store": "local",
    "ref": "uploads/bundle.tar.gz",
    "filename": "bundle.tar.gz",
    "mime": "application/gzip",
    "kind": "archive",
    "size": 40211,
    "sha256": "sha256:…",
    "lifecycle": "durable",
    "origin": "fs.file.put",
    "trust": "untrusted"
  },
  "archive": {
    "folder": "imports/latest",
    "count": 1,
    "source_deleted": true,
    "items": [
      {
        "__zf_type": "file_ref",
        "backend": "zebfs",
        "store": "local",
        "ref": "imports/latest/a.csv",
        "filename": "a.csv",
        "mime": "text/csv",
        "kind": "csv",
        "size": 120,
        "sha256": "sha256:…",
        "lifecycle": "durable",
        "origin": "fs.archive.extract",
        "trust": "untrusted"
      }
    ]
  }
}
```
