mruoss

mruoss

:zip.foldl() returns a :data_error when calling the GetBin function

Hello

I’m trying to process a .zip file “on-the-fly” using :zip.foldl/2. The way I understand the documentation, this function iterates over the files inside the ZIP. In the callback I get a function GetBin to get the content of the current file.

My Problem: When calling that function GetBin, I get a :data_error. Here’s the code:

iex> :zip.foldl(
  fn _, _, get_bin, _ -> dbg(get_bin.()) end, 
  nil, 
  String.to_charlist("path/to/my.zip")
) 

** (ErlangError) Erlang error: :data_error
    :zlib.inflate_nif(#Reference<0.1295784330.1440088067.199893>, 8192, 16384, 0)
    :zlib.dequeue_all_chunks_1/3
    :zlib.inflate/3
    :prim_zip.get_z_all/4

Just to rule out some things, this code works:

iex> :zip.foldl(
  fn filename, _, _, _ -> IO.puts(filename) end, 
  nil, 
  String.to_charlist("path/to/my.zip")
) 

file1
file2
file3
{:ok, :ok}

Version: IEx 1.15.4 (compiled with Erlang/OTP 26)

Does anybody know how to make this work?
Thanks!

Most Liked

crockwave

crockwave

There’s a typo in your example. It should be:

:zip.unzip(String.to_charlist("path/to/my.zip"), [:memory])

Where Next?

Popular in Questions Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
Kurisu
For example for a current url like http://localhost:4000/cosmetic/products?_utf8=✓&amp;query=perfume&amp;page=2, I would like to get: ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call t...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New

Other popular topics Top

malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement