View Source Unzip (unzip v0.7.2)
Module to get files out of a zip. Works with local and remote files
overview
Overview
Unzip tries to solve problem of accessing files from a zip which is
not local (Aws S3, sftp etc). It does this by simply separating file
system and zip implementation. Anything which implements
Unzip.FileAccess
can be used to get zip contents. Unzip relies on
the ability to seek and read of the file, This is due to the nature
of zip file. Files from the zip are read on demand.
usage
Usage
# Unzip.LocalFile implements Unzip.FileAccess
zip_file = Unzip.LocalFile.open("foo/bar.zip")
# `new` reads list of files by reading central directory found at the end of the zip
{:ok, unzip} = Unzip.new(zip_file)
# presents already read files metadata
file_entries = Unzip.list_entries(unzip)
# returns decompressed file stream
stream = Unzip.file_stream!(unzip, "baz.png")
Supports STORED and DEFLATE compression methods. Does not support zip64 specification yet
Link to this section Summary
Link to this section Types
Link to this section Functions
@spec file_stream!(t(), String.t()) :: Enumerable.t()
Returns decompressed file entry from the zip as a stream. file_name
must be complete file path. File is read in the chunks of 65k
@spec list_entries(t()) :: [Unzip.Entry.t()]
Returns list of files metadata. This does not make pread
call as metadata is already by new/1
.
See Unzip.Entry
for metadata fields
@spec new(Unzip.FileAccess.t()) :: {:ok, t()} | {:error, term()}
Reads zip metadata from the passed zip file.
zip
must implement Unzip.FileAccess
protocol.
Fetches the list of files present in the zip and other metadata by reading central directory found at the end of the zip.
Returns Unzip
struct which contains passed zip
struct and zip
metadata.