The
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 should end in "
Zip archives are created with the
To extract files from a zip archive, use the
To fold a function over all files in a zip archive, use the
To return a list of the files in a zip archive, use the
To print a list of files to the Erlang shell,
use either the
In some cases, it is desirable to open a zip archive, and to
unzip files from it file by file, without having to reopen the
archive. The functions
Zip64 archives are not currently supported.
Password-protected and encrypted archives are not currently supported
Only the DEFLATE (zlib-compression) and the STORE (uncompressed data) zip methods are supported.
The size of the archive is limited to 2 G-byte (32 bits).
Comments for individual files is not supported when creating zip archives. The zip archive comment for the whole zip archive is supported.
There is currently no support for altering an existing zip archive. To add or remove a file from an archive, the whole archive must be recreated.
zip_file()
The record
the name of the file
file info as in
the comment for the file in the zip archive
the offset of the file in the zip archive (used internally)
the compressed size of the file (the uncompressed size is found
in
zip_comment
The record
the comment for the zip archive
The
As synonyms, the functions
The file-list is a list of files, with paths relative to the current directory, they will be stored with this path in the archive. Files may also be specified with data in binaries, to create an archive directly from data.
Files will be compressed using the DEFLATE compression, as
described in the Appnote.txt file. However, files will be
stored without compression if they already are compressed.
The
It is possible to override the default behavior and
explicitly control what types of files should be
compressed by using the
The following options are available:
By default, the
Print an informational message about each file being added.
The output will not be to a file, but instead as a tuple
Add a comment to the zip-archive.
Use the given directory as current directory, it will be prepended to file names when adding them, although it will not be in the zip-archive. (Acting like a file:set_cwd/1, but without changing the global cwd property.)
Controls what types of files will be
compressed. It is by default set to
means that all files will be compressed (as long
as they pass the
means that only files with exactly these extensions will be compressed.
adds these extensions to the list of compress extensions.
deletes these extensions from the list of compress extensions.
Controls what types of files will be uncompressed. It is by
default set to
means that no files will be compressed.
means that files with these extensions will be uncompressed.
adds these extensions to the list of uncompress extensions.
deletes these extensions from the list of uncompress extensions.
The
If the
The following options are available:
By default, all files will be extracted from the zip
archive. With the
By default, the
By default, all existing files with the same name as file in
the zip archive will be overwritten. With the
Print an informational message as each file is being extracted.
Instead of extracting to the current directory, the
Use the given directory as current directory, it will be prepended to file names when extracting them from the zip-archive. (Acting like a file:set_cwd/1, but without changing the global cwd property.)
The
For 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
As synonyms, the functions
The result value is the tuple
The following options are available:
By default, the
The
The
The
The archive must be closed with
The
The
The files will be unzipped to memory or to file, depending on
the options given to the
The