View Source Gitly.Utils.Archive (gitly v0.1.0)

A module to handle archive operations.

This module provides functionality for building archive URLs, creating archive paths, downloading archives, and extracting them.

Summary

Functions

Builds an archive URL based on the given input.

Creates an archive path based on the given input.

Downloads an archive from the given URL and saves it to the given path.

Extracts an archive from the given file path to the given destination.

Functions

Link to this function

build_archive_url(input, format \\ :tar_gz)

View Source
@spec build_archive_url(map(), Gitly.Utils.Archive.Type.ext()) ::
  {:error, String.t()} | String.t()

Builds an archive URL based on the given input.

Parameters

  • input - A map containing archive information (must include :host).
  • format - The desired archive format (default: :tar_gz).

Returns

  • A string containing the built URL, or {:error, reason} if the operation fails.

Examples

iex> input = %{host: "github.com", owner: "elixir-lang", repo: "elixir", ref: "main"}
iex> Gitly.Utils.Archive.build_archive_url(input)
"https://github.com/elixir-lang/elixir/archive/main.tar.gz"
Link to this function

create_archive_path(map, opts \\ [])

View Source
@spec create_archive_path(map(), Gitly.opts()) :: Path.t()

Creates an archive path based on the given input.

Parameters

  • input - A map containing archive information (must include :host, :owner, :repo, and :ref).
  • opts - A keyword list of options:
    • :root - The root path (default: result of FS.root_path()).
    • :format - The archive format (default: :tar_gz).

Returns

  • A string containing the created archive path.

Examples

iex> input = %{host: "github.com", owner: "elixir-lang", repo: "elixir", ref: "main"}
iex> Gitly.Utils.Archive.create_archive_path(input, root: "/tmp")
"/tmp/github/elixir-lang/elixir/main.tar.gz"
Link to this function

download(url, path, opts \\ [])

View Source
@spec download(String.t(), Path.t(), Keyword.t()) ::
  {:ok, Path.t()} | {:error, String.t()}

Downloads an archive from the given URL and saves it to the given path.

Parameters

  • url - The URL of the archive to download.
  • path - The local path where the archive should be saved.
  • opts - A keyword list of options:
    • :retry - The retry strategy (default: :transient).

Returns

  • {:ok, path} if the download was successful.
  • {:error, reason} if the download failed.

Examples

iex> Gitly.Utils.Archive.download("https://example.com/archive.zip", "/tmp/archive.zip")
{:ok, "/tmp/archive.zip"}
Link to this function

extract(file_path, dest, opts \\ [])

View Source
@spec extract(Path.t(), Path.t(), Gitly.opts()) ::
  {:ok, Path.t()} | {:error, String.t()}

Extracts an archive from the given file path to the given destination.

Parameters

  • file_path - The path to the archive file.
  • dest - The destination directory where the archive should be extracted.
  • opts - A keyword list of options:
    • :force - Whether to force extraction even if the destination exists (default: false).
    • :overwrite - Whether to overwrite existing files (default: false).

Returns

  • {:ok, dest} if the extraction was successful.
  • {:error, reason} if the extraction failed.

Examples

iex> Gitly.Utils.Archive.extract("/tmp/archive.zip", "/tmp/extracted")
{:ok, "/tmp/extracted"}