Library to read zip file in a stream. Zip file binary stream -> stream of {:new_file,name} or uncompressed_bin
Erlang zlib library only allows deflate decompress stream. But Erlang zip library does not allow content streaming.
For instance if you have a zip with multiple files, you can use the stream to do:
File.stream!("myfile.zip", [], 500)
|> ZipStream.unzip
|> Stream.reduce(nil,fn
{:new_file,name},_current->name
binary,file_name->
#DO SOMTHING WITH the binary chunk of file_name
file_name
end)
An other example: your zip contains only one file, in this case you
can simply do the following to get a standard binary stream of this
on file. (drop the {:new_file,_}
of the single file)
binstream = File.stream!("myfile.zip", [], 500)
|> ZipStream.unzip
|> Stream.drop(1)
This library does not handle all possible zip files, in particular:
- The zip archive contains uncompressed data or data not compressed with the deflate algorithm
- The zip archive contains data with the
data_descriptor
format - The zip archive is a zip64 to handle files bigger than (2^32 4Go)
The package can be installed as:
-
Add zip_stream to your list of dependencies in
mix.exs
:def deps do [{:zip_stream, "~> 0.1.0"}] end
-
Ensure zip_stream is started before your application:
def application do [applications: [:zip_stream]] end