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

A module to handle archive types.

This module provides functions to work with various archive formats, including zip, tar, tar.gz, tgz, tar.bz2, and tar.xz.

Summary

Functions

Ensures the given extension has a leading dot.

Returns the archive type as an atom from the given path.

Returns the archive type as an atom from the given string.

Returns the archive type as a string from the given type.

Removes the archive extension from the given path.

Removes the leading dot from the given extension.

Checks if the given path is a valid archive.

Types

@type ext() :: :zip | :tar | :tar_gz | :tgz | :tar_bz2 | :tar_xz

Functions

@spec ensure_leading_dot(binary()) :: binary()

Ensures the given extension has a leading dot.

Parameters

  • ext - The extension string.

Returns

  • The extension string with a leading dot.

Examples

iex> Gitly.Utils.Archive.Type.ensure_leading_dot("zip")
".zip"

iex> Gitly.Utils.Archive.Type.ensure_leading_dot(".tar.gz")
".tar.gz"
@spec from_path(Path.t()) :: ext() | :unknown

Returns the archive type as an atom from the given path.

Parameters

  • path - The file path to check.

Returns

  • The archive type as an atom (:zip, :tar, etc.) or :unknown if not recognized.

Examples

iex> Gitly.Utils.Archive.Type.from_path("example.tar.gz")
:tar_gz

iex> Gitly.Utils.Archive.Type.from_path("example.txt")
:unknown
Link to this function

from_string(string, dot \\ true)

View Source
@spec from_string(binary(), boolean()) :: ext() | :unknown

Returns the archive type as an atom from the given string.

Parameters

  • string - The string representing the archive extension.
  • dot - Whether the string includes a leading dot (default: true).

Returns

  • The archive type as an atom (:zip, :tar, etc.) or :unknown if not recognized.

Examples

iex> Gitly.Utils.Archive.Type.from_string(".zip")
:zip

iex> Gitly.Utils.Archive.Type.from_string("tar.gz", false)
:tar_gz

iex> Gitly.Utils.Archive.Type.from_string("rar")
:unknown
Link to this function

from_type(type, dot \\ true)

View Source
@spec from_type(ext(), boolean()) :: binary() | :unknown

Returns the archive type as a string from the given type.

Parameters

  • type - The archive type as an atom.
  • dot - Whether to include a leading dot in the result (default: true).

Returns

  • The archive extension as a string or :unknown if not recognized.

Examples

iex> Gitly.Utils.Archive.Type.from_type(:zip)
".zip"

iex> Gitly.Utils.Archive.Type.from_type(:tar_gz, false)
"tar.gz"

iex> Gitly.Utils.Archive.Type.from_type(:unknown)
:unknown
@spec trim_extension(Path.t()) :: Path.t()

Removes the archive extension from the given path.

Parameters

  • path - The file path.

Returns

  • The path without the archive extension.

Examples

iex> Gitly.Utils.Archive.Type.trim_extension("example.tar.gz")
"example"

iex> Gitly.Utils.Archive.Type.trim_extension("example.txt")
"example.txt"
@spec trim_leading_dot(binary()) :: binary()

Removes the leading dot from the given extension.

Parameters

  • ext - The extension string.

Returns

  • The extension string without a leading dot.

Examples

iex> Gitly.Utils.Archive.Type.trim_leading_dot(".zip")
"zip"

iex> Gitly.Utils.Archive.Type.trim_leading_dot("tar.gz")
"tar.gz"
@spec valid?(Path.t()) :: boolean()

Checks if the given path is a valid archive.

Parameters

  • path - The file path to check.

Returns

  • true if the path ends with a valid archive extension, false otherwise.

Examples

iex> Gitly.Utils.Archive.Type.valid?("example.zip")
true

iex> Gitly.Utils.Archive.Type.valid?("example.txt")
false