View Source OctoFetch.Downloader behaviour (OctoFetch v0.3.0)

This module defines the callbacks that a GitHub downloader needs to implement in order to fetch artifacts from GitHub. base_url/2 and default_version/0 are automatically implemented for you when you use the OctoFetch module, but you always have the option to override their default implementations.

Link to this section Summary

Callbacks

This callback generates the base URL for the artifact based on the provided GitHub repo and the requested version. The default implementation from OctoFetch is

This callback returns the default version that sould be downloaded if the user does not override the version. It will default to the value of :latest_version as provided to the OctoFetch __using__/1 macro.

This callback acts as a pass through to the OctoFetch module for the downloader implementation. See OctoFetch.download/3 for supported opts.

This function must be implemented by your downloader module and is used to dynamically generate the name of the download artifact based on the user's running environment. For example, for Litestream you would do something like so to ensure that users download the proper artifact

This callback is invoked whenever a file is written to the filesystem as a result from the download. This callback may be invoked several times if the download was an archive file and contained multiple files.

This callback is invoked prior to a file being downloaded. This gives you the opportunity to skip the download if you so chose by returning :skip. Otherwise, return :cont to continue with the download.

Link to this section Types

@type arch() :: :arm64 | :amd64
@type download_result() ::
  {:ok, successful_files :: list(), failed_files :: list()}
  | {:error, String.t()}
  | :skip
@type os() :: :linux | :darwin | :freebsd | :windows

Link to this section Callbacks

Link to this callback

base_url(github_repo, version)

View Source
@callback base_url(github_repo :: String.t(), version :: String.t()) :: String.t()

This callback generates the base URL for the artifact based on the provided GitHub repo and the requested version. The default implementation from OctoFetch is:

def base_url(github_repo, version) do
  "https://github.com/#{github_repo}/releases/download/v#{version}/"
end
@callback default_version() :: String.t()

This callback returns the default version that sould be downloaded if the user does not override the version. It will default to the value of :latest_version as provided to the OctoFetch __using__/1 macro.

Link to this callback

download(output_dir, opts)

View Source
@callback download(output_dir :: String.t(), opts :: Keyword.t()) :: download_result()

This callback acts as a pass through to the OctoFetch module for the downloader implementation. See OctoFetch.download/3 for supported opts.

Link to this callback

download_name(version, operation_system, architecture)

View Source
@callback download_name(
  version :: String.t(),
  operation_system :: os(),
  architecture :: arch()
) ::
  String.t()

This function must be implemented by your downloader module and is used to dynamically generate the name of the download artifact based on the user's running environment. For example, for Litestream you would do something like so to ensure that users download the proper artifact:

def download_name(version, :darwin, arch), do: "litestream-v#{version}-darwin-#{arch}.zip"
def download_name(version, :linux, arch), do: "litestream-v#{version}-linux-#{arch}.tar.gz"
@callback post_write_hook(file :: String.t()) :: :ok

This callback is invoked whenever a file is written to the filesystem as a result from the download. This callback may be invoked several times if the download was an archive file and contained multiple files.

Link to this callback

pre_download_hook(file, output_dir)

View Source
@callback pre_download_hook(file :: String.t(), output_dir :: String.t()) :: :cont | :skip

This callback is invoked prior to a file being downloaded. This gives you the opportunity to skip the download if you so chose by returning :skip. Otherwise, return :cont to continue with the download.