Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unzipping files with Elixir throws :data_error

Tags:

elixir

I'm downloading a file from Google Cloud Storage (https://cloud.google.com/storage/docs/json_api/v1/objects/get#parameters)

The binary contents of the file are returned on the response body. Using :zlib.uncompress throws me

** (ErlangError) erlang error: :data_error

I've checked the contents of the file by saving it on disk and extracting manually.

Is there another way to unzip a file in elixir/erlang without using unix commands?

Edit:

Inspecting the binaries gave me an ok

r.body |> inspect(binaries: :as_binaries) |> IO.puts
<<31, 139, 8, 0, 0, 0, 0, 0, 0, 0, 212, 253, 91, 115, 27, 73, 178, 53, 10, 190, 207, 175, 104, 219, 207, 95, 193, 50, 174, 153, 57, 111, 188, 64, 36, 27, 44, 146, 6, 146, 170, 22, 95, 218, 212, 85, 234, 106, 157, 93, ...>>
:ok
like image 299
paulorcdiniz Avatar asked Jul 10 '26 03:07

paulorcdiniz


1 Answers

You can try using zip from erlang. The function you are looking for is unzip

:zip.unzip(zipped_file)
like image 100
coderVishal Avatar answered Jul 11 '26 21:07

coderVishal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!