Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Zlib inflate an list of bytes in Elixir?

Tags:

zlib

elixir

Given a binary in Elixir which represents a compressed file, how can I pass them to Erlang's zlib to inflate?

compressed = <<120, 218, 237, 125, 123, 115, 28, 71, 126, ...>>

I have tried:

z = :zlib.open()
uncompressed = :zlib.inflate(z, compressed)
:zlib.close(z)

Error returned is:

** (ErlangError) erlang error: :einval
               :zlib.call/3     
               :zlib.inflate/2

Expects an "iodata" as an argument, so maybe I just need to convert it?

like image 344
Don Pflaster Avatar asked Oct 09 '15 12:10

Don Pflaster


1 Answers

After opening the zlib port, you need to call inflateInit on it before calling inflate:

z = :zlib.open()
:zlib.inflateInit(z)
uncompressed = :zlib.inflate(z, compressed)
:zlib.close(z)
like image 142
legoscia Avatar answered Nov 01 '22 21:11

legoscia