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
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"
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
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
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
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"
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"
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