Universal compression and archive utilities.
Wraps system-level tools behind a consistent {:ok, result} | {:error, reason}
interface. Supports: zip, tar (gzip/bzip2/xz/zstd), gzip, gunzip, zstd, xz,
bzip2, 7z, rar. Auto-detects format from file extension.
Security
All paths passed to shell commands are properly escaped. Passwords are
passed via command-line flags (-P for zip/unzip, -p for 7z) instead
of shell piping to avoid shell injection vectors.
Summary
Functions
Compresses a single file with the specified algorithm. Replaces the original with the compressed version.
Creates a 7z archive from source paths.
Creates a RAR archive from source paths.
Decompresses a single file. Algorithm auto-detected from extension.
Detects the archive or compression type from a file extension.
Extracts an archive, auto-detecting the format from its extension.
Extracts a 7z archive.
Extracts a RAR archive.
Decompresses a gzip file, keeping the original.
Compresses a file with gzip (replaces original with .gz).
Lists the contents of an archive. Auto-detects format.
Creates a tar archive. Supports compression: :gzip, :bzip2, :xz, :zstd, :none.
Extracts a tar archive. Compression auto-detected from extension.
Extracts a zip archive.
Creates a zip archive from source paths. Supports password.
Types
Functions
@spec compress(binary(), single_algo()) :: {:ok, binary()} | {:error, binary()}
Compresses a single file with the specified algorithm. Replaces the original with the compressed version.
Creates a 7z archive from source paths.
Creates a RAR archive from source paths.
@spec decompress(binary(), single_algo()) :: {:ok, binary()} | {:error, binary()}
Decompresses a single file. Algorithm auto-detected from extension.
@spec detect_type(binary()) :: archive_type()
Detects the archive or compression type from a file extension.
Examples
iex> Apero.Compress.detect_type("backup.tar.gz")
:tar_gz
iex> Apero.Compress.detect_type("data.zst")
:zst
iex> Apero.Compress.detect_type("unknown.xyz")
:unknown
Extracts an archive, auto-detecting the format from its extension.
Options
:output— destination directory (default: current directory):password— optional password for zip/7z/rar
Examples
Apero.Compress.extract("backup.tar.gz", output: "/tmp/restore")
Extracts a 7z archive.
Extracts a RAR archive.
Decompresses a gzip file, keeping the original.
Compresses a file with gzip (replaces original with .gz).
Lists the contents of an archive. Auto-detects format.
Returns a list of file name strings.
Creates a tar archive. Supports compression: :gzip, :bzip2, :xz, :zstd, :none.
Extracts a tar archive. Compression auto-detected from extension.
Extracts a zip archive.
Creates a zip archive from source paths. Supports password.