Module hex_tarball
Data Types
checksum()
checksum() = binary()
contents()
contents() = #{filename() => binary()}
filename()
filename() = string()
files()
files() = [{filename(), filename() | binary()}]
metadata()
metadata() = map()
tarball()
tarball() = binary()
Function Index
create/2 | Creates a package tarball. |
create_docs/1 | Creates a docs tarball. |
format_checksum/1 | Returns base16-encoded representation of checksum. |
format_error/1 | Converts an error reason term to a human-readable error message string. |
unpack/2 | Unpacks a package tarball. |
unpack_docs/2 | Unpacks a documentation tarball. |
Function Details
create/2
create(Metadata::metadata(), Files::files()) -> {ok, {tarball(), checksum()}} | {error, term()}
Creates a package tarball.
Returns the binary of the tarball the "inner checksum" and "outer checksum". The inner checksum is deprecated in favor of the inner checksum.
Examples:
> Metadata = #{<<"name">> => <<"foo">>, <<"version">> => <<"1.0.0">>},
> Files = [{"src/foo.erl", <<"-module(foo).">>}],
> hex_tarball:create(Metadata, Files).
{ok, #{tarball => <<86,69,...>>,
outer_checksum => <<40,32,...>>,
inner_checksum => <<178,12,...>>}}
create_docs/1
create_docs(Files::files()) -> {ok, tarball()}
Creates a docs tarball.
Examples:
> Files = [{"doc/index.html", <<"Docs">>}],
> hex_tarball:create_docs(Files).
{ok, <<86,69,...>>}
format_checksum/1
format_checksum(Checksum::checksum()) -> binary()
Returns base16-encoded representation of checksum.
format_error/1
format_error(X1::term()) -> string()
Converts an error reason term to a human-readable error message string.
unpack/2
unpack(Tarball::tarball(), Output::memory) -> {ok, #{checksum => checksum(), metadata => metadata(), contents => contents()}} | {error, term()}
Unpacks a package tarball.
Remember to verify the outer tarball checksum against the registry checksum returned from hex_repo:get_package(Config, Package)
.
Examples:
> hex_tarball:unpack(Tarball, memory).
{ok,#{outer_checksum => <<...>>,
contents => [{"src/foo.erl",<<"-module(foo).">>}],
metadata => #{<<"name">> => <<"foo">>, ...}}}
> hex_tarball:unpack(Tarball, "path/to/unpack").
{ok,#{outer_checksum => <<...>>,
metadata => #{<<"name">> => <<"foo">>, ...}}}`''
<a name="unpack_docs-2"></a>
### unpack_docs/2 ###
<pre><code>
unpack_docs(Tarball::<a href="#type-tarball">tarball()</a>, Output::memory) -> {ok, <a href="#type-contents">contents()</a>} | {error, term()}
</code></pre>
<br />
Unpacks a documentation tarball.
Examples:
hex_tarball:unpack_docs(Tarball, memory). {ok, [{"index.html", <<"<!doctype>">>}, ...]} hex_tarball:unpack_docs(Tarball, "path/to/unpack"). ok