Guides

Create archives

Pack files and folders into an archive from the peel CLI or the Rust library, and rewrite archives you already have, without leaving a half-written file behind.

Peel 1.4.0 · Snack Studio · Updated

Which surface writes

Rind can create archives from the peel CLI, from the Rust library and from the MCP server, whose create tool is confined to the roots you grant. The C library has no create call. The commands that rewrite an existing archive (edit, solidify, unsolidify, upgrade, recompress, restore, train) are CLI commands, and edit, solidify, unsolidify, upgrade and train also have Rust functions. The CLI examples below run in a folder holding a project directory.

Create an archive

TerminalShell
peel create out.zip project

The format comes from the output name, and nothing else decides it. create takes any mix of files and folders. A folder is added recursively under its own name, and a file goes in under its base name. Symbolic links are not followed and are not stored.

Output name Format Notes
.zip, .cbz, .jar, .war, .ear ZIP All plain ZIPs. EPUB, APK, USDZ and 3MF are refused: they need layouts a plain ZIP does not have.
.7z 7z LZMA2.
.tar tar No compression.
.tar.gz, .tgz tar with gzip
.tar.bz2, .tbz2, .tbz tar with bzip2
.tar.xz, .txz tar with xz
.tar.zst, .tzst tar with zstd
.gz, .bz2, .xz, .zst, .zstd one compressed file Exactly one input file. More than one fails with exit 1.

Any other name, such as .rar, .dmg, .tar.br or .tar.lz4, fails with unsupported (exit 7) and nothing is written. Rind reads many more formats than it writes, as the formats page shows.

peel create out.zip project
zip → out.zip (8 files)
$ peel create out.7z project
7z → out.7z (8 files)
$ peel create out.tar.zst project --level 19
tar.zst → out.tar.zst (8 files)
$ peel create readme.gz project/README.md
gz → readme.gz (1 files)
$ peel create out.zip project -n -j; echo "exit $?"
{"error":"already_exists","detail":"create out.zip: io error: out.zip already exists: out.zip already exists"}
exit 14
Real output from peel 1.4.0, recorded 2026-11-26.

The archive is written to a hidden temporary file beside the output and renamed into place when it is complete. The output is either the old file or the whole new one, and a failed create removes its temporary file. By default create replaces an existing output. Pass -n to fail instead with already_exists (exit 14), as the last command above does. -j prints { "output", "format", "entries" }, where entries counts files.

The same call in Rust takes a list of inputs and an overwrite flag:

Rust
use peel_core::create_archive_with;
use std::path::{Path, PathBuf};

let inputs = vec![PathBuf::from("project"), PathBuf::from("README.md")];
// overwrite = false refuses to replace an existing file.
let made = create_archive_with(Path::new("site.zip"), &inputs, None, false)?;   // CreateResult
println!("{} files in {}", made.entries, made.output);

create_archive(output, inputs, password) always replaces. create_archive_split and create_archive_opts add volumes and the options below.

Compression level

--level N trades size for time. The range depends on the format, and a level outside it is refused, not clamped.

Format Levels Default
zstd (.zst, .tar.zst) 1 to 19 3
xz (.xz, .tar.xz) 0 to 9 6
gzip, bzip2, ZIP 1 to 9 6
tar, 7z none

peel create out.tar project --level 3 fails with “tar has no compression level to set”, and so does .7z. ZIP level 0 is out of range. In Rust, set CreateOptions::level.

--long turns on zstd long-distance matching with a 128 MiB window. It makes .zst and .tar.zst denser on large inputs with distant repetition, and it is refused on every other format.

Passwords

A password encrypts a ZIP or a 7z with AES-256. ZIP uses WinZip AES-256, which 7-Zip, WinZip and Keka open. A 7z also encrypts its header, so the file names are hidden too. A ZIP leaves names readable.

TerminalShell
printf '%s' "$PASSPHRASE" | peel create secret.7z project --password-stdin
printf 'correct horse battery staple' | peel create secret.7z project --password-stdin
7z → secret.7z (8 files)
$ peel list secret.7z; echo "exit $?"
peel: list secret.7z: password required: this archive is encrypted
exit 3
$ printf 'correct horse battery staple' | peel list secret.7z --password-stdin | head -3
11 entries
project/
project/README.md
project/docs/
Real output from peel 1.4.0, recorded 2026-11-26.

Pass the password the way you would to extract: --password-stdin or --password-fd N first, then PEEL_PASSWORD, and -p last because it shows in the process list. A password on any other format is refused rather than written unprotected: peel create out.tar.gz project --password-stdin fails with exit 1 and no file.

An empty password means none. If standard input is empty, or you pass -p ’’, the CLI writes an unencrypted archive and says nothing. The library refuses an empty password. In a script, confirm with peel inspect that encrypted is true. peel test passes on an unencrypted archive too, so it proves nothing here.

In Rust, CreateOptions::verify reopens the finished archive with the password and removes it if the check fails. It is off by default and skipped for split volumes.

Rust
use peel_core::{create_archive_opts, CreateOptions};
use std::path::{Path, PathBuf};

let opts = CreateOptions {
    password: Some("correct horse battery staple".into()),   // ZIP and 7z only
    overwrite: true,    // the default is false, unlike the CLI
    verify: true,
    ..Default::default()
};
create_archive_opts(Path::new("secret.7z"), &[PathBuf::from("project")], &opts)?;

To add AES-256 to an archive you already have, use upgrade.

Split into volumes

--volume-size cuts the finished archive into numbered parts. It accepts sizes such as 500K, 100M or 1G, or a byte count, and works for ZIP, 7z and every .tar.*. The single-stream formats are refused, as is a size of 0 or one that would need more than 999 parts.

peel create split.zip photos --volume-size 100K
zip → split.zip (2 files)
$ ls -l split.zip.* | awk '{print $5, $9}'
102400 split.zip.001
98220 split.zip.002
$ peel test split.zip.001
OK   Zip  3 entries, 2 verified, 0 unchecked  split.zip.001
Real output from peel 1.4.0, recorded 2026-11-26.

The parts are a plain byte split: cat split.zip.* > split.zip gives back the original. Open a set by its first name, split.zip.001, and Rind joins the rest. Without -n, an older set of the same name is removed first, so a stale part is never joined onto the new archive. With -n, an existing .001 fails with exit 14. In Rust, set CreateOptions::volume_size to a byte count.

Solid and non-solid

Two commands convert between the forms. Both write a new file at -o FILE, which must not exist, and never change the input. Either takes a password for an encrypted input, and the output stays encrypted with the same one. Symbolic links are not carried, and the command says how many it skipped.

TerminalShell
peel unsolidify photos.7z -o photos-working.zip -j

The result is { "input", "output", "direction", "format", "entries", "encrypted", "links_skipped" }. In Rust these are unsolidify(input, output, password) and solidify(...), which take Option<&Secret>.

Check solidity before relying on it. peel inspect -j reports is_solid for a 7z. In 1.4.0 the 7z that create and solidify write reports is_solid: false. If density is what you want, compare a .tar.xz or .tar.zst –level 19 of your own data against the 7z before choosing.

Edit a ZIP in place

peel edit changes a ZIP without re-creating it. -a PATH adds a file or replaces the member with the same name, and -r NAME removes a member. Both repeat.

cp demo.zip work.zip
$ peel edit work.zip -a note.txt -r project/README.md
work.zip: +1 added, 0 replaced, 1 removed, 10 kept
$ peel unsolidify photos.7z -o photos-working.zip -j
{
  "input": "photos.7z",
  "output": "photos-working.zip",
  "direction": "unsolidify",
  "format": "zip",
  "entries": 2,
  "encrypted": false,
  "links_skipped": 0
}
Real output from peel 1.4.0, recorded 2026-11-26.

The edit line reports one file added, none replaced, one removed and ten kept. The last command is the conversion from the previous section. The file you add goes in under its base name, so -a cannot place a file inside project/. The Rust function can: ZipEdit::add holds (path on disk, member name) pairs.

Rust
use peel_core::{edit_zip, ZipEdit};
use std::path::{Path, PathBuf};

let edit = ZipEdit {
    add: vec![(PathBuf::from("note.txt"), "project/docs/note.txt".into())],
    remove: vec!["project/README.md".into()],
};
let result = edit_zip(Path::new("work.zip"), &edit, None)?;   // EditResult: added, replaced, removed, kept

The edit writes a verified copy beside the archive and renames it over the original, so a failure leaves the original as it was. Removing a name that is not in the archive fails with exit 1. Only ZIP is editable: for a 7z or a tar, convert with unsolidify, edit, and convert back if you need to. A ZIP with encrypted members is refused, because the AES markers would be lost in the copy. In Rust, edit_zip’s password argument encrypts the files being added and is not applied to kept members.

Add or strengthen encryption

peel upgrade re-wraps an archive you can open in AES-256 and writes it to a new file. The extension of -o picks the form: .zip for WinZip AES-256, .7z for 7z AES-256 with an encrypted header. The original is never changed, and an existing output is not replaced.

TerminalShell
printf '%s' "$NEW" | peel upgrade old.zip --new-password-stdin -o strong.7z -j

The new password comes from --new-password-stdin or --new-password-fd N. For an encrypted source, give its password with --password-stdin or --password-fd. Note that -o is a file path here, although the global help calls it a folder. The result is { "entries", "old_encryption", "new_encryption", "output" }. In Rust: upgrade_protection(source, source_password, dest, new_password), or upgrade_protection_with_profile with StrongProfile::SevenZAes256 for a .7z. Both refuse an empty new password.

Train a zstd dictionary

A dictionary helps when you compress many small, similar files, such as JSON events or log lines. peel train builds one from a folder of samples, and create --dict uses it on a standalone .zst.

peel train events -o events.zdict
events.zdict (2048 bytes; limit 2048 bytes, sized to the samples; 300 sample files, 32781 bytes)
$ peel create events.zst events.jsonl --dict events.zdict
zst → events.zst (1 files)
$ ls events.zst*
events.zst
events.zst.dict
Real output from peel 1.4.0, recorded 2026-11-26.

Without --max-size, the dictionary is sized to the samples: about a hundredth of their total bytes, between 2 KiB and 110 KiB, because a dictionary larger than it can pay back makes the output bigger. -j prints { "output", "size", "max_size", "auto_sized", "sample_files", "sample_bytes" }. Training needs plenty of samples: a handful of near-identical files fails with a training error.

The dictionary is written beside the output as <output>.dict, and the archive cannot be read without it. If the .dict file is missing, an extract fails with io (exit 16) and “Dictionary mismatch”. --dict is refused for .tar.zst and every other format. Measure the saving on your own data before adopting a dictionary.

Rust
use peel_core::{create_archive_opts, train_dictionary, CreateOptions};
use std::path::{Path, PathBuf};

let dict = train_dictionary(Path::new("events"), None)?;   // regular files directly under the folder
std::fs::write("events.zdict", &dict.bytes)?;
let opts = CreateOptions { dict: Some(PathBuf::from("events.zdict")), ..Default::default() };
create_archive_opts(Path::new("events.zst"), &[PathBuf::from("events.jsonl")], &opts)?;

It is a standard zstd dictionary, so zstd -D reads it too.

Recompress a gzip file

peel recompress turns a gzip, zlib or raw DEFLATE file into a smaller file that restores the exact original. It writes nothing unless the result is smaller and Rind can prove, with a round trip, that it restores byte for byte. peel restore reverses it. Both write to -o FILE, which must not exist.

peel recompress docs.gz -o docs.rc
docs.gz (gzip): 182 -> 179 bytes, 1.6% smaller; wrote docs.rc
$ peel restore docs.rc -o docs-restored.gz
docs.rc (gzip): 179 -> 182 bytes, verified; wrote docs-restored.gz
$ cmp docs.gz docs-restored.gz && echo identical
identical
Real output from peel 1.4.0, recorded 2026-11-26.

The saving depends on how the original was compressed, and it can be small, as above. When nothing can be gained, the command says “Left as is”, writes nothing and exits 0. With -j, recompress prints framing, original_size, payload_size, recompressed_size, recompressed and a timing_ms block, and restore prints restored_size and verified. Inputs over 512 MiB are refused.

Next: recover a damaged archive, or script all of this in CI.