mruoss

mruoss OP

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!

First 6 of 6 Posts Switch mode

al2o3cr

al2o3cr

I’m not sure that actually rules much out - the directory is separate from the data in an zip file, so that version isn’t trying to read most of the file.

mruoss

mruoss OP

Gotcha. But this works, too:

iex> :zip.unzip(String.to_charlist("path/to/my.zip", [:memory]))
{:ok, [{'file1', "..."}, {'file2', "..."}, {'file3', "..."}]}
olivermt

olivermt

Edit: need more coffee, thought you were MAKING zips :joy:

moogle19

moogle19

It looks like it depends on the zip if this works or not.

If I create a zip with the build-in macOS function, I get the same error.
If I use zip from the terminal, it works.

This seems to be a problem in the macOS Archive Utility.

mruoss

mruoss OP

Hmm… possible. Although I would be surprised if my zip was created on Mac OS. But I don’t know for sure.

crockwave

crockwave

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

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

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
michallepicki
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New

Other Trending Topics Top

ElixirConf
Lightning Talk: Jacob Swanner - Put your Scaller (Named Correctly) | ElixirConf US 2025 https://www.youtube.com/watch?v=dqqZSSxs-MA Co...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement