I’m trying to parse contents of a file in zip file. My idea is to use Unzip to stream contents (the unpacked file might be too large for my taste), and transform it on the fly.
However, something’s weird:
Unzip.file_stream(handle, entry_name)
|> Stream.map(fn e -> IO.iodata_to_binary(e) end)
|> Enum.to_list
[
<<208, 161, 208, 190, 208, 186, 208, 190, 208, 187, 208, 190, 208, 178, 44,
208, 161, 208, 181, 209, 128, 208, 179, 208, 181, 208, 185, 44, 208, 144,
208, 189, 208, 176, 209, 130, 208, 190, 208, 187, 209
This works. Replace it with Stream_flat_map
or Enum.take(2)
or Stream.transform
, and
Unzip.file_stream(handle, entry_name)
|> Stream.transform([], fn e, acc -> {e |> IO.iodata_to_binary, acc} end )
|> Stream.run()
** (ErlangError) Erlang error: :data_error
:zlib.inflateEnd_nif(#Reference<0.60592435.1843265537.68376>)
(unzip 0.11.0) lib/unzip.ex:188: anonymous fn/1 in Unzip.decompress/2
(elixir 1.17.0) lib/stream.ex:1039: Stream.do_transform_inner_list/7
(elixir 1.17.0) lib/stream.ex:1038: Stream.do_transform_inner_list/7
(elixir 1.17.0) lib/stream.ex:1055: Stream.do_transform_inner_enum/7
(elixir 1.17.0) lib/stream.ex:690: Stream.run/1
iex:58: (file)
Something fails somewhere, and I can’t for the life of me figure out where