This module archives and extracts files to and from a zip
archive. The zip format is specified by the "ZIP Appnote.txt" file,
available on the PKWARE web site
The zip module supports zip archive versions up to 6.1. However, password-protection and Zip64 are not supported.
By convention, the name of a zip file is to end with
To create zip archives, use function
To extract files from a zip archive, use function
To fold a function over all files in a zip archive, use function
To return a list of the files in a zip archive, use function
To print a list of files to the Erlang shell, use function
Sometimes it is desirable to open a zip archive, and to
unzip files from it file by file, without having to reopen the
archive. This can be done by functions
Zip64 archives are not supported.
Password-protected and encrypted archives are not supported.
Only the DEFLATE (zlib-compression) and the STORE (uncompressed data) zip methods are supported.
The archive size is limited to 2 GB (32 bits).
Comments for individual files are not supported when creating zip archives. The zip archive comment for the whole zip archive is supported.
Changing a zip archive is not supported. To add or remove a file from an archive, the whole archive must be recreated.
The record
The record
The filename
File information as in
The comment for the file in the zip archive
The file offset in the zip archive (used internally)
The size of the compressed file (the size of the uncompressed
file is found in
The name of a zip file.
These options are described in
As returned by
Calls
Both
The
Example:
> Name = "dummy.zip". "dummy.zip" > {ok, {Name, Bin}} = zip:create(Name, [{"foo", <<"FOO">>}, {"bar", <<"BAR">>}], [memory]). {ok,{"dummy.zip", <<80,75,3,4,20,0,0,0,0,0,74,152,97,60,171,39,212,26,3,0, 0,0,3,0,0,...>>}} > {ok, FileSpec} = zip:foldl(fun(N, I, B, Acc) -> [{N, B(), I()} | Acc] end, [], {Name, Bin}). {ok,[{"bar",<<"BAR">>, {file_info,3,regular,read_write, {{2010,3,1},{19,2,10}}, {{2010,3,1},{19,2,10}}, {{2010,3,1},{19,2,10}}, 54,1,0,0,0,0,0}}, {"foo",<<"FOO">>, {file_info,3,regular,read_write, {{2010,3,1},{19,2,10}}, {{2010,3,1},{19,2,10}}, {{2010,3,1},{19,2,10}}, 54,1,0,0,0,0,0}}]} > {ok, {Name, Bin}} = zip:create(Name, lists:reverse(FileSpec), [memory]). {ok,{"dummy.zip", <<80,75,3,4,20,0,0,0,0,0,74,152,97,60,171,39,212,26,3,0, 0,0,3,0,0,...>>}} > catch zip:foldl(fun("foo", _, B, _) -> throw(B()); (_,_,_,Acc) -> Acc end, [], {Name, Bin}). <<"FOO">>
The result value is the tuple
One option is available:
By default, this function opens the zip file in
Prints all filenames in the zip archive
Prints filenames and information about all files in the zip archive
If argument
Options:
By default, all files are extracted from the zip
archive. With option
By default, this function opens the
zip file in
By default, all files with the same name as files in
the zip archive are overwritten. With option
Prints an informational message for each extracted file.
Instead of extracting to the current directory,
the result is given as a list of tuples
Uses the specified directory as current directory. It is
prepended to filenames when extracting them from the
zip archive. (Acting like
Creates a zip archive containing the files specified in
Files are compressed using the DEFLATE compression, as
described in the "Appnote.txt" file. However, files are
stored without compression if they are already compressed.
It is possible to override the default behavior and control
what types of files that are to be compressed by using options
To trigger file compression, its extension must match with the
Options:
By default, this function opens the
zip file in mode
Prints an informational message about each added file.
The output is not to a file, but instead as a tuple
Adds a comment to the zip archive.
Uses the specified directory as current work directory
(
Controls what types of files to be compressed. Defaults to
All files are compressed (as long
as they pass the
Only files with exactly these extensions are compressed.
Adds these extensions to the list of compress extensions.
Deletes these extensions from the list of compress extensions.
Controls what types of files to be uncompressed. Defaults to
No files are compressed.
Files with these extensions are uncompressed.
Adds these extensions to the list of uncompress extensions.
Deletes these extensions from the list of uncompress extensions.
Closes a zip archive, previously opened with
Extracts one or all files from an open archive.
The files are unzipped to memory or to file, depending on
the options specified to function
Returns the file list of an open zip archive. The first returned element is the zip archive comment.
Opens a zip archive, and reads and saves its directory. This
means that later reading files from the archive is
faster than unzipping files one at a time with
The archive must be closed with
The