Skip to content

Instantly share code, notes, and snippets.

@ryochin
Last active September 13, 2020 07:18
Show Gist options
  • Save ryochin/576c5b46a7e7b0e1fc8052540facedd7 to your computer and use it in GitHub Desktop.
Save ryochin/576c5b46a7e7b0e1fc8052540facedd7 to your computer and use it in GitHub Desktop.
Elixir: gunzip
@spec gunzip(binary) :: {:ok, binary} | {:error, term}
def gunzip(data) when is_binary(data) do
try do
z = :zlib.open()
:ok = :zlib.inflateInit(z, 16 + 15)
result =
z
|> :zlib.inflate(data)
|> List.flatten()
|> Enum.join()
:ok = :zlib.inflateEnd(z)
:ok = :zlib.close(z)
{:ok, result}
rescue
e -> {:error, inspect(e)}
end
end
@ryochin
Copy link
Author

ryochin commented Sep 13, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment