zstream v0.4.0 Zstream View Source
Module for reading and writing ZIP file stream
Example
Zstream.zip([
Zstream.entry("report.csv", Stream.map(records, &CSV.dump/1)),
Zstream.entry("catfilm.mp4", File.stream!("/catfilm.mp4", [], 512), coder: Zstream.Coder.Stored)
])
|> Stream.into(File.stream!("/archive.zip"))
|> Stream.run
File.stream!("archive.zip", [], 512)
|> Zstream.unzip()
|> Enum.reduce(%{}, fn
{:entry, %Zstream.Entry{name: file_name} = entry}, state -> state
{:data, data}, state -> state
{:data, :eof}, state -> state
end)
Link to this section Summary
Link to this section Types
Link to this section Functions
entry(name, enum, options \\ [])
View Sourceentry(String.t(), Enumerable.t(), Keyword.t()) :: entry()
Creates a ZIP file entry with the given name
The enum
could be either lazy Stream
or List
. The elements in enum
should be of type iodata
Options
:coder
(module | {module, list}) - The compressor that should be used to encode the data. Available options areZstream.Coder.Deflate
- use deflate compressionZstream.Coder.Stored
- store without any compressionDefaults to
Zstream.Coder.Deflate
:encryption_coder
({module, keyword}) - The encryption module that should be used to encrypt the data. Available options areZstream.EncryptionCoder.Traditional
- use tranditional zip encryption scheme.:password
key should be present in the options. Example{Zstream.EncryptionCoder.Traditional, password: "secret"}
Zstream.EncryptionCoder.None
- no encryptionDefaults to
Zstream.EncryptionCoder.None
:mtime
(DateTime) - File last modication time. Defaults to system local time.
Unzips file stream
returns a new stream which emits the following tuples for each zip entry
{:entry
, Zstream.Entry.t/0
} - Indicates a new file entry.
{:data
, iodata/0
| :eof
} - one or more data tuples will be emitted for each entry. :eof
indicates end of data tuples for current entry.
NOTES
Unzip doesn't support all valid zip files. Zip file format allows the writer to write the file size info after the file data, which allows the writer to zip streams with unknown size. But this prevents the reader from unzipping the file in a streaming fashion, because to find the file size one has to go to the end of the stream. Ironcially, if you use Zstream to zip a file, the same file can't be unzipped using Zstream.
- doesn't support file which uses data descriptor header
- doesn't support encrypted file
Creates a ZIP file stream
entries are consumed one by one in the given order