---
id: file--stream-compress
title: "Stream compress"
summary: "Packs incoming `ViaFileStream` records into an archive (ZIP, GZip, TAR, TAR.GZ or TAR.LZ) and emits the archive as a new `ViaFileStream`. The files of one batch (e.g. the entries of a decompressed archive, the files of one Collect files run) go into one archive; a file without a batch becomes its own archive."
audience: user
keywords: "input, output, compressiontype, archivepassword, batchscope"
---
# Stream compress

Packs incoming `ViaFileStream` records into an archive (ZIP, GZip, TAR, TAR.GZ or TAR.LZ) and emits the archive as a new `ViaFileStream`. The files of one batch (e.g. the entries of a decompressed archive, the files of one Collect files run) go into one archive; a file without a batch becomes its own archive.

## Pins

| Pin | Kind | Types | Description |
|---|---|---|---|
| Input | input | `Viaducta.Plugins.Files.Types.ViaFileStream` | File to add. `Name` becomes the entry name, `Stream` the content. |
| Output | output | `Viaducta.Plugins.Files.Types.ViaFileStream` | The finished archive (in-memory stream). |

## Configuration

| Field | Type | Default | Description |
|---|---|---|---|
| `CompressionType` | dropdown: `0` GZip, `1` Zip, `2` Tar, `3` TarGz, `4` BZip2, `5` LZIP | `0` | Archive format. `4` BZip2 is not supported: the flow fails to start. `5` LZIP produces a TAR compressed with LZip (`.tar.lz`). |
| `ArchivePassword` | string | | Not used, see Notes. |
| `BatchScope` | batch scope selector | empty | Which batch goes into one archive. Empty = the closest batch producer upstream. A component id of a batch producer upstream = the batches of that producer. `None` = ignore batches, every file becomes its own archive. |

## Behaviour

- Files in a batch (see `BatchScope`) are written into the archive of their batch when they arrive (the input stream is read right away, it may be closed afterwards). When the whole batch has been processed the archive is finished and emitted; when the batch failed it is discarded. The archive record carries the metadata of the last file and stays in the batch, so batch consumers behind it (Write file, ...) include it before they commit. The compression type of the first file of the batch is used.
- A file without a batch (or `BatchScope` `None`) is emitted right away as an archive with one entry.
- The emitted `ViaFileStream` has `Name` = batch label (e.g. the source archive or file name, Sql query run) or, without a batch, the input file name, plus the extension (`.zip`, `.gz`, `.tar`, `.tar.gz`, `.tar.lz`); `Extension`, `Size` and `Stream` (positioned at 0) are set. `FilePath` and dates are not set.
- If writing a file into the archive fails, the batch fails and the rest of its files are dropped.

## Notes

- `ArchivePassword` is ignored; archives are never encrypted.
- GZip holds only one file: a second file in a GZip batch fails the batch. For several files use Zip or a TAR variant.
- The whole archive is built in memory; avoid very large batches.

## Example

```json
{ "CompressionType": 1 }
```

Read file (`*.tar.gz`) → Stream decompress → **Stream compress** → Write file: every tar.gz repacked as zip. The entries stay in the Read file batch, so each input file gives one archive.
