Trebejo.Compress (Trebejo v2.0.0)

Copy Markdown View Source

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.

This module is a facade that delegates to per-format sub-modules: Trebejo.Compress.Format, .Zip, .Tar, .Gzip, .Algorithm, .SevenZ, .Rar.

Summary

Functions

Compresses a single file with the specified algorithm. Replaces the original with the compressed version. Delegates to Trebejo.Compress.Algorithm.compress/2.

Creates a 7z archive from source paths.

Creates a RAR archive from source paths.

Decompresses a single file. Algorithm auto-detected from extension. Delegates to Trebejo.Compress.Algorithm.decompress/2.

Detects the archive or compression type from a file extension. Delegates to Trebejo.Compress.Format.detect_type/1.

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. Delegates to Trebejo.Compress.Tar.tar/3.

Extracts a tar archive. Compression auto-detected from extension.

Extracts a zip archive. Delegates to Trebejo.Compress.Zip.unzip/2.

Creates a zip archive from source paths. Supports password. Delegates to Trebejo.Compress.Zip.zip/3.

Types

archive_type()

@type archive_type() :: Trebejo.Compress.Format.archive_type()

single_algo()

@type single_algo() :: Trebejo.Compress.Algorithm.single_algo()

Functions

compress(file, algo)

@spec compress(binary(), single_algo()) :: {:ok, binary()} | {:error, binary()}

Compresses a single file with the specified algorithm. Replaces the original with the compressed version. Delegates to Trebejo.Compress.Algorithm.compress/2.

create_7z(output, files, opts \\ [])

@spec create_7z(binary(), [binary()], keyword()) ::
  {:ok, binary()} | {:error, binary()}

Creates a 7z archive from source paths.

create_rar(output, files, opts \\ [])

@spec create_rar(binary(), [binary()], keyword()) ::
  {:ok, binary()} | {:error, binary()}

Creates a RAR archive from source paths.

decompress(file, algo)

@spec decompress(binary(), single_algo()) :: {:ok, binary()} | {:error, binary()}

Decompresses a single file. Algorithm auto-detected from extension. Delegates to Trebejo.Compress.Algorithm.decompress/2.

detect_type(path)

@spec detect_type(binary()) :: archive_type()

Detects the archive or compression type from a file extension. Delegates to Trebejo.Compress.Format.detect_type/1.

extract(file, opts \\ [])

@spec extract(
  binary(),
  keyword()
) :: {:ok, binary()} | {:error, binary()}

Extracts an archive, auto-detecting the format from its extension.

Options

  • :output — destination directory (default: current directory)
  • :password — optional password for zip/7z/rar

extract_7z(file, opts \\ [])

@spec extract_7z(
  binary(),
  keyword()
) :: {:ok, binary()} | {:error, binary()}

Extracts a 7z archive.

extract_rar(file, opts \\ [])

@spec extract_rar(
  binary(),
  keyword()
) :: {:ok, binary()} | {:error, binary()}

Extracts a RAR archive.

gunzip(file)

@spec gunzip(binary()) :: {:ok, binary()} | {:error, binary()}

Decompresses a gzip file, keeping the original.

gzip(file)

@spec gzip(binary()) :: {:ok, binary()} | {:error, binary()}

Compresses a file with gzip (replaces original with .gz).

list(file)

@spec list(binary()) :: {:ok, [binary()]} | {:error, binary()}

Lists the contents of an archive. Auto-detects format.

tar(output, input, opts \\ [])

@spec tar(binary(), binary(), keyword()) :: {:ok, binary()} | {:error, binary()}

Creates a tar archive. Supports compression: :gzip, :bzip2, :xz, :zstd, :none. Delegates to Trebejo.Compress.Tar.tar/3.

untar(file, opts \\ [])

@spec untar(
  binary(),
  keyword()
) :: {:ok, binary()} | {:error, binary()}

Extracts a tar archive. Compression auto-detected from extension.

unzip(file, opts \\ [])

@spec unzip(
  binary(),
  keyword()
) :: {:ok, binary()} | {:error, binary()}

Extracts a zip archive. Delegates to Trebejo.Compress.Zip.unzip/2.

zip(output, files, opts \\ [])

@spec zip(binary(), [binary()], keyword()) :: {:ok, binary()} | {:error, binary()}

Creates a zip archive from source paths. Supports password. Delegates to Trebejo.Compress.Zip.zip/3.