Skip to content

Instantly share code, notes, and snippets.

@ijunaid8989
Forked from nroi/extract_tar_from_binary.ex
Created September 12, 2022 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ijunaid8989/075359c72771e2b8e583b7005425434e to your computer and use it in GitHub Desktop.
Save ijunaid8989/075359c72771e2b8e583b7005425434e 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