Skip to content

Instantly share code, notes, and snippets.

@nroi
Created April 21, 2019 12:29
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save nroi/d4b0716a987c46534c04eb6611b78703 to your computer and use it in GitHub Desktop.
Save nroi/d4b0716a987c46534c04eb6611b78703 to your computer and use it in GitHub Desktop.
Decompressing a tar.gz archive in Elixir with Erlang's :erl_tar module.
@doc"""
Returns a map containing all files and their contents from the compressed tar archive.
"""
def extract_tar_from_binary(binary) do
with {:ok, files} <- :erl_tar.extract({:binary, binary}, [:memory, :compressed]) do
files
|> Enum.map(fn {filename, content} -> {to_string(filename), content} end)
|> Map.new
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment