Portability | so far only tested on GHC |
---|---|
Stability | unstable |
Maintainer | John MacFarlane < jgm at berkeley dot edu > |
Codec.Archive.Zip
Contents
Description
The zip-archive library provides functions for creating, modifying, and extracting files from zip archives.
Certain simplifying assumptions are made about the zip archives: in particular, there is no support for 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.
As an example of the use of the library, a standalone zip archiver and extracter, Zip.hs, is provided in the source distribution.
For more information on the format of zip archives, consult http://www.pkware.com/documents/casestudies/APPNOTE.TXT
- data Archive = Archive {
- zEntries :: [Entry]
- zSignature :: Maybe ByteString
- zComment :: ByteString
- data Entry = Entry {
- eRelativePath :: FilePath
- eCompressionMethod :: CompressionMethod
- eLastModified :: Integer
- eCRC32 :: Word32
- eCompressedSize :: Word32
- eUncompressedSize :: Word32
- eExtraField :: ByteString
- eFileComment :: ByteString
- eInternalFileAttributes :: Word16
- eExternalFileAttributes :: Word32
- eCompressedData :: ByteString
- data CompressionMethod
- = Deflate
- | NoCompression
- data ZipOption
- emptyArchive :: Archive
- toArchive :: ByteString -> Archive
- fromArchive :: Archive -> ByteString
- filesInArchive :: Archive -> [FilePath]
- addEntryToArchive :: Entry -> Archive -> Archive
- deleteEntryFromArchive :: FilePath -> Archive -> Archive
- findEntryByPath :: FilePath -> Archive -> Maybe Entry
- fromEntry :: Entry -> ByteString
- toEntry :: FilePath -> Integer -> ByteString -> Entry
- readEntry :: [ZipOption] -> FilePath -> IO Entry
- writeEntry :: [ZipOption] -> Entry -> IO ()
- addFilesToArchive :: [ZipOption] -> Archive -> [FilePath] -> IO Archive
- extractFilesFromArchive :: [ZipOption] -> Archive -> IO ()
Data structures
data Archive
Structured representation of a zip archive, including directory information and contents (in lazy bytestrings).
Constructors
Archive | |
Fields
|
data Entry
Representation of an archived file, including content and metadata.
Constructors
Entry | |
Fields
|
data CompressionMethod
Compression methods.
Constructors
Deflate | |
NoCompression |
Instances
Eq CompressionMethod | |
Read CompressionMethod | |
Show CompressionMethod |
data ZipOption
Options for addFilesToArchive
and extractFilesFromArchive
.
Constructors
OptRecursive | Recurse into directories when adding files |
OptVerbose | Print information to stderr |
A zip archive with no contents.
Pure functions for working with zip archives
toArchive :: ByteString -> Archive
Reads an Archive
structure from a raw zip archive (in a lazy bytestring).
fromArchive :: Archive -> ByteString
Writes an Archive
structure to a raw zip archive (in a lazy bytestring).
filesInArchive :: Archive -> [FilePath]
Returns a list of files in a zip archive.
addEntryToArchive :: Entry -> Archive -> Archive
Adds an entry to a zip archive, or updates an existing entry.
deleteEntryFromArchive :: FilePath -> Archive -> Archive
Deletes an entry from a zip archive.
findEntryByPath :: FilePath -> Archive -> Maybe Entry
Returns Just the zip entry with the specified path, or Nothing.
Arguments
:: FilePath | File path for entry |
-> Integer | Modification time for entry (seconds since unix epoch) |
-> ByteString | Contents of entry |
-> Entry |
Create an Entry
with specified file path, modification time, and contents.
IO functions for working with zip archives
writeEntry :: [ZipOption] -> Entry -> IO ()
Writes contents of an Entry
to a file.
addFilesToArchive :: [ZipOption] -> Archive -> [FilePath] -> IO Archive
Add the specified files to an Archive
. If OptRecursive
is specified,
recursively add files contained in directories. If OptVerbose
is specified,
print messages to stderr.
extractFilesFromArchive :: [ZipOption] -> Archive -> IO ()
Extract all files from an Archive
, creating directories
as needed. If OptVerbose
is specified, print messages to stderr.
Note that the last-modified time is set correctly only in POSIX,
not in Windows.