The zip-archive library provides functions for creating, modifying, and extracting files from zip archives. The zip archive format is documented in http://www.pkware.com/documents/casestudies/APPNOTE.TXT.
Certain simplifying assumptions are made about the zip archives: in particular, there is no support for strong encryption, zip files that span multiple disks, ZIP64, OS-specific file attributes, or compression methods other than Deflate. However, the library should be able to read the most common zip archives, and the archives it produces should be readable by all standard unzip programs.
Archives are built and extracted in memory, so manipulating large zip files will consume a lot of memory. If you work with large zip files or need features not supported by this library, a better choice may be zip, which uses a memory-efficient streaming approach. However, zip can only read and write archives inside instances of MonadIO, so zip-archive is a better choice if you want to manipulate zip archives in “pure” contexts.
As an example of the use of the library, a standalone zip archiver and extracter is provided in the source distribution.
* writEntry behavior change: Improve raising of UnsafePath error (#55).
Previously we raised this error spuriously when archives were unpacked
outside the working directory. Now we raise it if eRelativePath contains
".." as a path component, or eRelativePath path is an absolute path and
there is no separate destination directory. (Note that `/foo/bar` is fine
as a path as long as a destination directory, e.g. `/usr/local`, is
* Implement read-only support for PKWARE encryption (Sergii Rudchenko).
The "traditional" PKWARE encryption is a symmetric encryption
algorithm described in zip format specification in section 6.1.
This change allows to extract basic "password-protected" entries from
ZIP files. Note that the standard file extraction function
extractFilesFromArchive does not decrypt entries (it will raise
an exception if it encounters an encrypted entry). To handle
archives with encrypted entries, use the new function
+ Add eEncryptionMethod field to Entry.
+ Add EncryptionMethod type.
+ Add function isEncryptedEntry.
+ Add function fromEncryptedEntry.
* Add CannotWriteEncryptedEntry constructor to ZipException.
* Add UnsafePath to ZipException (#50).
* writeEntry: raise UnsafePath exception for unsafe paths (#50).
This prevents malicious zip files from overwriting paths
above the working directory.
* Add Paths_zip_archive to autogen-modules.
* Clarify README and cabal description.
* Specify cabal-version: 2.0. Otherwise we get an unknown build
tool error using `build-depends` without a custom Setup.hs.
* Change build-type to simple. Retain 'build-tools: unzip' in
test stanza, though now it doesn't do anything except give a
hint to external tools. If unzip is not found in the path,
the test suite prints a message and counts the test that
requires unzip as succeeding (see #51).
* Remove dependency on old-time (typedrat).
* Drop splitBase flag and support for base versions < 3.
* Move 'build-tools: unzip' from library stanza to test stanza.
unzip should only be required for testing, not for regular
builds of the library.
* Make build-tools stanza conditional on non-windows. Closes #44.
* Use custom-setup stanza and specify build-tools. Closes #41.
* Use createSymbolicLink instead of createFileLink in tests. This allows
us to lower the directory lower bound (#40).
* Fixes for handling of symbolic links (#39, Tommaso Piazza).
* Fixes for symbolic link tests, and additional tests.
* Add ZipOption to preserve symbolic links (#37, Tommaso Piazza).
Add OptPreserveSymbolicLinks constructor to ZipOption. If this option
is set, symbolic links will be preserved. Symbolic links are not
supported on Windows.
* Require binary >= 0.6 (#36).
* Improve exit handling in zip-archive program.
* readEntry: Read file as a strict ByteString. This avoids
problems on Windows, where the file handle wasn't being closed.
* Added appveyor.yml to do continuous testing on Windows.
* Test suite: remove need for external zip program (#35).
Instead of creating an archive with zip, we now store
a small externally created zip archive to use for testing.
* Don't use a custom build (#28).
* Renamed executable Zip -> zip-archive, added --debug option.
The --debug option prints the intermediate Haskell data structure.
* Fix check for unix file attributes (#34).
Previously attributes would not always be preserved
for files in zip archives.
* Bump bytestring lower bound so toStrict is guaranteed (Benjamin Landers).
* Fix bug in `OptLocation` handling (EugeneN). When using
`OptLocation folder False` (for adding files to an archive into a
folder without preserving full path hierarchy), original files'
names were ignored, resulting in all the files getting the same name.
* Fix `toArchive` so it doesn't use too much memory when a data
data descriptor holds the size (Michael Stahl, #29).
The size fields in the local file headers may not contain valid values,
in which case the sizes are stored in a "data descriptor" that follows
the file data. Previously handling this case required reading the
entire archive is a `[Word8]` list. With this change, `getWordsTilSig`
iteratively reads chunks as strict ByteStrings and converts them to
a lazy ByteString at the end.
* Test suite: use withTempDir to create temporary directory.
This should help fix problems some have encountered with the
test suite leaving a temporary directory behind.
* Fix test suite so it runs on Windows.
* Zip executable: get version from cabal `Paths_zip_archive` (#27).
* Set `eVersionMadeBy` to 0 (default) in `toEntry`, since we are
setting external attributes to 0. See jgm/pandoc#2822.
Only to `eVersionMadeBy` to UNIX if we actually read file
attributes on a UNIX system.
* Support preservation of file modes on Posix (Dan Aloni, #26).
* Add `eVersionMadeBy` field to `Entry` (API change).
* Export `ZipException` (API change).
* `fromEntry` no longer checks for CRC32 match. Previously, it issued
`error` if the match failed. CRC32 match is now checked in `writeEntry`
instead, and a `CRC32Exception` is raised if the checksum doesn't match.
* Test suite: return nonzero status if there are test failures.
Previously we mistakenly did this only on 'errors', not failures.
* Test suite: don't use -9 with zip as it isn't always available.
* Use .travis.yml that builds on both stack and cabal.
* Declared test suite's dependency on 'zip' using custom Setup.lhs (#21,#22).
* Removed hard-coded path to zip in test suite (#21).
* Removed misplaced build-depends in cabal file.
* Allow compilation with binary >= 0.5. Note that toArchiveOrFail
is not safe when compiled against binary < 0.7; it will never
return a Left value, and will raise an error if parsing fails,
just like toArchive. This is documented in the haddocks.
This is ugly, but justified by the need to have a version
of zip-archive that compiles against older versions of binary.
* Make sure all path comparisons compare normalized paths.
So, findEntryByPath "foo" will find something stored as "./foo"
in the zip container.
* Better normalization of file paths: "./foo/bar" and "foo/./bar"
are now treated the same, for example. Note that we do not
yet treat "foo/../bar" and "bar" as the same.
* Removed lower bound on directory (>= 1.2), which caused build
failures with GHC 7.4 and 7.6.
* Added travis script for automatic testing on 3 GHC versions.
* Require binary >= 0.7 and directory >= 1.2. The newer binary
is needed to provide toArchiveOrFail. The other change is
mainly for convenience, to avoid lots of ugly conditional
* Export new function `toArchiveOrFail`. Closes #17.
* Set general purpose bit flag to use UTF8 in local file header.
Otherwise we get a mismatch between the flag in the central
directory and the flag in the local file header, which causes some
programs not to be able to extract the files. Closes #19.
* Fix a stack overflow in getWordsTillSig (Tristan Ravitch).
* Set bit 11 in the file header to ensure other programs
recognize UTF-8 encoded file names (Tobias Brandt).
* Added OptLocation, to specify the path to which a file
is to be added when readEntry is used (Stephen McIntosh).