-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Bindings to libzip, a library for manipulating zip archives. -- -- libzip is a C library for reading, creating, and modifying zip -- archives. This package allows to use it from Haskell code. @package LibZip @version 0.2.0 module Codec.Archive.LibZip.Types -- | Handler of the open zip file. type Zip = Ptr C'zip -- | Handler of an open file in the zip archive. type ZipFile = Ptr C'zip_file -- | Handler of data source for new files in the zip archive. type ZipSource = Ptr C'zip_source -- | File statistics expressed in native Haskell types. data ZipStat ZipStat :: String -> Int -> Word -> UTCTime -> Int -> Int -> ZipCompMethod -> ZipEncryptionMethod -> ZipStat zs'name :: ZipStat -> String zs'index :: ZipStat -> Int zs'crc :: ZipStat -> Word zs'mtime :: ZipStat -> UTCTime zs'size :: ZipStat -> Int zs'comp_size :: ZipStat -> Int zs'comp_method :: ZipStat -> ZipCompMethod zs'encryption_method :: ZipStat -> ZipEncryptionMethod -- | Convert marshalled stat record. toZipStat :: C'zip_stat -> IO ZipStat -- | Flags for opening an archive. data OpenFlag -- | Create an archive if it does not exist. CreateFlag :: OpenFlag -- | Error if the archive already exists. ExclFlag :: OpenFlag -- | Check archive's consistency and error on failure. CheckConsFlag :: OpenFlag -- | Flags for accessing files in the archive. Please consult -- libzip documentation about their use. data FileFlag -- | Ignore case on name lookup. FileNOCASE :: FileFlag -- | Ignore directory component. FileNODIR :: FileFlag -- | Read the compressed data. FileCOMPRESSED :: FileFlag -- | Read the original data, ignore changes. FileUNCHANGED :: FileFlag -- | Force recompression of data. FileRECOMPRESS :: FileFlag -- | libzip error codes. data ZipError -- | No error. ErrOK :: ZipError -- | Multi-disk zip archives not supported. ErrMULTIDISK :: ZipError -- | Renaming temporary file failed. ErrRENAME :: ZipError -- | Closing zip archive failed. ErrCLOSE :: ZipError -- | Seek error. ErrSEEK :: ZipError -- | Read error. ErrREAD :: ZipError -- | Write error. ErrWRITE :: ZipError -- | CRC error. ErrCRC :: ZipError -- | Containing zip archive was closed. ErrZIPCLOSED :: ZipError -- | No such file. ErrNOENT :: ZipError -- | File already exists. ErrEXISTS :: ZipError -- | Can't open file. ErrOPEN :: ZipError -- | Failure to create temporary file. ErrTMPOPEN :: ZipError -- | Zlib error. ErrZLIB :: ZipError -- | Malloc error. ErrMEMORY :: ZipError -- | Entry has been changed. ErrCHANGED :: ZipError -- | Compression method not supported. ErrCOMPNOTSUPP :: ZipError -- | Premature EOF. ErrEOF :: ZipError -- | Invalid argument. ErrINVAL :: ZipError -- | Not a zip archive. ErrNOZIP :: ZipError -- | Internal error. ErrINTERNAL :: ZipError -- | Zip archive inconsistent. ErrINCONS :: ZipError -- | Can't remove file. ErrREMOVE :: ZipError -- | Entry has been deleted. ErrDELETED :: ZipError -- | Compression methods. data ZipCompMethod -- | Better of deflate or store. CompDEFAULT :: ZipCompMethod -- | Stored (uncompressed). CompSTORE :: ZipCompMethod -- | Shrunk. CompSHRINK :: ZipCompMethod -- | Reduced with factor 1 CompREDUCE_1 :: ZipCompMethod -- | Reduced with factor 2 CompREDUCE_2 :: ZipCompMethod -- | Reduced with factor 3 CompREDUCE_3 :: ZipCompMethod -- | Reduced with factor 4 CompREDUCE_4 :: ZipCompMethod -- | Imploded. CompIMPLODE :: ZipCompMethod -- | Deflated. CompDEFLATE :: ZipCompMethod -- | Deflate64. CompDEFLATE64 :: ZipCompMethod -- | PKWARE imploding. CompPKWARE_IMPLODE :: ZipCompMethod -- | Compressed using BZIP2 algorithm. CompBZIP2 :: ZipCompMethod -- | LZMA (EFS) CompLZMA :: ZipCompMethod -- | Compressed using IBM TERSE (new). CompTERSE :: ZipCompMethod -- | IBM LZ77 z Architecture (PFS). CompLZ77 :: ZipCompMethod -- | WavPack compressed data. CompWAVPACK :: ZipCompMethod -- | PPMd version I, Rev 1. CompPPMD :: ZipCompMethod -- | Encryption methods. data ZipEncryptionMethod -- | Not encrypted. EncryptNONE :: ZipEncryptionMethod -- | Traditional PKWARE encryption. EncryptTRAD_PKWARE :: ZipEncryptionMethod -- | Unknown algorithm. EncryptUNKNOWN :: ZipEncryptionMethod combine :: (Enum a, Num b) => [a] -> b instance Typeable ZipError instance Show ZipEncryptionMethod instance Eq ZipEncryptionMethod instance Show ZipCompMethod instance Eq ZipCompMethod instance Eq ZipError instance Show FileFlag instance Eq FileFlag instance Show OpenFlag instance Eq OpenFlag instance Show ZipStat instance Eq ZipStat instance Enum ZipEncryptionMethod instance Enum ZipCompMethod instance Show ZipError instance Exception ZipError instance Enum ZipError instance Enum FileFlag instance Enum OpenFlag -- | This module is a backwards compatible replacement for -- Codec.Archive.LibZip module of LibZip 0.0.x. This API is -- deprecated, please don't use it in new code. module Codec.Archive.LibZip.LegacyZeroZero -- | Handler of the open zip file. type Zip = Ptr C'zip -- | Handler of an open file in the zip archive. type ZipFile = Ptr C'zip_file -- | Flags for opening an archive. data OpenFlag -- | Create an archive if it does not exist. CreateFlag :: OpenFlag -- | Error if the archive already exists. ExclFlag :: OpenFlag -- | Check archive's consistency and error on failure. CheckConsFlag :: OpenFlag -- | Flags for accessing files in the archive. Please consult -- libzip documentation about their use. data FileFlag -- | Ignore case on name lookup. FileNOCASE :: FileFlag -- | Ignore directory component. FileNODIR :: FileFlag -- | Read the compressed data. FileCOMPRESSED :: FileFlag -- | Read the original data, ignore changes. FileUNCHANGED :: FileFlag -- | Force recompression of data. FileRECOMPRESS :: FileFlag -- | libzip error codes. data ZipError -- | No error. ErrOK :: ZipError -- | Multi-disk zip archives not supported. ErrMULTIDISK :: ZipError -- | Renaming temporary file failed. ErrRENAME :: ZipError -- | Closing zip archive failed. ErrCLOSE :: ZipError -- | Seek error. ErrSEEK :: ZipError -- | Read error. ErrREAD :: ZipError -- | Write error. ErrWRITE :: ZipError -- | CRC error. ErrCRC :: ZipError -- | Containing zip archive was closed. ErrZIPCLOSED :: ZipError -- | No such file. ErrNOENT :: ZipError -- | File already exists. ErrEXISTS :: ZipError -- | Can't open file. ErrOPEN :: ZipError -- | Failure to create temporary file. ErrTMPOPEN :: ZipError -- | Zlib error. ErrZLIB :: ZipError -- | Malloc error. ErrMEMORY :: ZipError -- | Entry has been changed. ErrCHANGED :: ZipError -- | Compression method not supported. ErrCOMPNOTSUPP :: ZipError -- | Premature EOF. ErrEOF :: ZipError -- | Invalid argument. ErrINVAL :: ZipError -- | Not a zip archive. ErrNOZIP :: ZipError -- | Internal error. ErrINTERNAL :: ZipError -- | Zip archive inconsistent. ErrINCONS :: ZipError -- | Can't remove file. ErrREMOVE :: ZipError -- | Entry has been deleted. ErrDELETED :: ZipError -- | 8-bit unsigned integer type data Word8 :: * -- | Open zip archive, do something, and close the archive. withZip :: String -> [OpenFlag] -> (Zip -> IO a) -> IO a -- | Get names of the files in archive. getFiles :: Zip -> [FileFlag] -> IO [String] -- | Get size of the file in archive. getFileSize :: Zip -> String -> [FileFlag] -> IO Int -- | Read uncompressed file from the archive. Produce a strict ByteString. readZipFile :: Zip -> String -> [FileFlag] -> IO ByteString -- | Read uncompressed file from the archive. Produce a list of -- Word8. readZipFile' :: Zip -> String -> [FileFlag] -> IO [Word8] -- | Read beginning of the uncompressed file from the archive. Produce a -- strict ByteString. readZipFileHead :: Zip -> String -> [FileFlag] -> Int -> IO ByteString -- | Read beginning of the uncompressed file from the archive. Produce a -- list of Word8. readZipFileHead' :: Zip -> String -> [FileFlag] -> Int -> IO [Word8] -- | Open zip archive specified by path and return its handler on -- success. open :: String -> [OpenFlag] -> IO Zip -- | Close zip archive. close :: Zip -> IO () -- | Return the number of files in the archive. get_num_files :: Zip -> IO Int -- | Get name of file by index. get_name :: Zip -> Int -> [FileFlag] -> IO String -- | Open file in zip archive for reading. fopen :: Zip -> String -> [FileFlag] -> IO ZipFile -- | Open n-th file in zip archive for reading. fopen_index :: Zip -> Int -> [FileFlag] -> IO ZipFile -- | Close file in zip archive. fclose :: ZipFile -> IO () -- | Read from file in zip archive. fread :: ZipFile -> Int -> IO [Word8] -- | Wrapper to catch library errors. catchZipError :: IO a -> (ZipError -> IO a) -> IO a -- | Return True if path is a file name, not a directory name (does not end -- with /). isFile :: String -> Bool -- | Return True if path is a directory name (ends with /). isDir :: String -> Bool -- | Monadic interface to libzip. -- -- Most of the operations on zip archive happen within Archive -- monad (see withArchive). Partial reading of the files in the -- archive may be performed from within Entry monad (see -- fromFile). Both Archive and Entry are monad -- transformers over IO, and allow for IO with single and double -- lifting respectingly. -- -- Note: LibZip does not handle text encodings. Even if its API accepts -- Strings (e.g. in sourceBuffer), character codes above -- 255 should not be used. The user is responsible of proper encoding the -- text data. -- -- Examples -- -- List files in the zip archive: -- --
-- import System.Environment (getArgs) -- import Codec.Archive.LibZip -- -- main = do -- (zipfile:_) <- getArgs -- files <- withArchive [] zipfile $ fileNames [] -- mapM_ putStrLn files ---- -- Create a zip archive and a add file to the archive: -- --
-- import System.Environment (getArgs) -- import Codec.Archive.LibZip -- -- main = do -- (zipfile:_) <- getArgs -- withArchive [CreateFlag] zipfile $ do -- zs <- sourceBuffer "Hello World!" -- addFile "hello.txt" zs ---- -- Extract and print a file from the zip archive: -- --
-- import System.Environment (getArgs) -- import Codec.Archive.LibZip -- -- main = do -- (zipfile:file:_) <- getArgs -- bytes <- withArchive [] zipfile $ fileContents [] file -- putStrLn bytes ---- -- See also an implementation of a simple zip archiver hzip.hs -- in the examples/ directory of the source distribution. module Codec.Archive.LibZip -- | Monadic computation with a zip archive. See withArchive. type Archive a = StateT Zip IO a -- | Monadic computation to read from open archive entries. See -- fromFile and fromFileIx. type Entry a = StateT (ZipFile, Int, [FileFlag]) (StateT Zip IO) a -- | File statistics expressed in native Haskell types. data ZipStat ZipStat :: String -> Int -> Word -> UTCTime -> Int -> Int -> ZipCompMethod -> ZipEncryptionMethod -> ZipStat zs'name :: ZipStat -> String zs'index :: ZipStat -> Int zs'crc :: ZipStat -> Word zs'mtime :: ZipStat -> UTCTime zs'size :: ZipStat -> Int zs'comp_size :: ZipStat -> Int zs'comp_method :: ZipStat -> ZipCompMethod zs'encryption_method :: ZipStat -> ZipEncryptionMethod -- | Top-level wrapper for operations with an open archive. -- withArchive opens and closes the file automatically. On error -- it throws ZipError. withArchive :: [OpenFlag] -> FilePath -> Archive a -> IO a -- | Get archive handler. Throw ErrINVAL if the archive is closed. getZip :: Archive Zip -- | Get the number of entries in the archive. numFiles :: Archive Int -- | Get name of an entry in the archive by its index. fileName :: [FileFlag] -> Int -> Archive FilePath -- | Locate an entry (get its index) in the archive by its name. nameLocate :: [FileFlag] -> FilePath -> Archive (Maybe Int) -- | Get names of all entries (files and directories) in the archive. fileNames :: [FileFlag] -> Archive [FilePath] -- | Get size of a file in the archive. fileSize :: [FileFlag] -> FilePath -> Archive Int -- | Get size of a file in the archive (by index). fileSizeIx :: [FileFlag] -> Int -> Archive Int -- | Get information about a file in the archive. fileStat :: [FileFlag] -> FilePath -> Archive ZipStat -- | Get information about a file in the archive (by index). fileStatIx :: [FileFlag] -> Int -> Archive ZipStat -- | Delete file from the archive. deleteFile :: [FileFlag] -> FilePath -> Archive () -- | Delete file (referenced by position index) from the archive. deleteFileIx :: Int -> Archive () -- | Rename file in the archive. renameFile :: [FileFlag] -> FilePath -> FilePath -> Archive () -- | Rename file (referenced by position index) in the archive. renameFileIx :: Int -> FilePath -> Archive () -- | Add a file to the archive. addFile :: FilePath -> ZipSource -> Archive Int -- | Add a directory to the archive. addDirectory :: FilePath -> Archive Int -- | Replace a file in the archive. replaceFile :: [FileFlag] -> FilePath -> ZipSource -> Archive () -- | Replace a file in the archive (referenced by position index). replaceFileIx :: Int -> ZipSource -> Archive () -- | Create a data source. Note: input is converted to [Word8] -- internally. sourceBuffer :: (Enum a) => [a] -> Archive ZipSource -- | Create a data source from a file. sourceFile :: FilePath -> Int -> Int -> Archive ZipSource -- | Create a data source from a file in the zip archive. sourceZip :: [FileFlag] -> Zip -> Int -> Int -> Int -> Archive ZipSource -- | Wrapper for a user-provided pure function to be used with -- sourcePure. Data size should be known in advance -- (srcSize). The function should support reading by chunks -- (readSrc). data (Enum a, Storable a, Storable st) => PureSource a st PureSource :: st -> Int -> Maybe UTCTime -> (Int -> st -> Maybe (Int, [a], st)) -> PureSource a st -- | Initial state of the source. srcState :: PureSource a st -> st -- | Total size of the data. srcSize :: PureSource a st -> Int -- | Modification time (current time if Nothing). srcMTime :: PureSource a st -> Maybe UTCTime -- | Read a chunk of the data, return Just the size of data read, -- the data themselves and the new state of the source, or -- Nothing on error. readSrc :: PureSource a st -> Int -> st -> Maybe (Int, [a], st) -- | Create a data source from a PureSource. Note: input of -- [a] is converted to [Word8] internally. sourcePure :: (Enum a, Storable a, Storable st) => PureSource a st -> Archive ZipSource -- | Get zip archive comment. getComment :: [FileFlag] -> Archive (Maybe String) -- | Set zip archive comment. setComment :: String -> Archive () -- | Remove zip archive comment. removeComment :: Archive () -- | Get comment for a file in the archive. getFileComment :: [FileFlag] -> FilePath -> Archive (Maybe String) -- | Get comment for a file in the archive (referenced by position index). getFileCommentIx :: [FileFlag] -> Int -> Archive (Maybe String) -- | Set comment for a file in the archive. setFileComment :: [FileFlag] -> FilePath -> String -> Archive () -- | Set comment for a file in the archive (referenced by position index). setFileCommentIx :: Int -> String -> Archive () -- | Remove comment for a file in the archive. removeFileComment :: [FileFlag] -> FilePath -> Archive () -- | Remove comment for a file in the archive (referenced by position -- index). removeFileCommentIx :: Int -> Archive () -- | Undo changes to a file in the archive. unchangeFile :: [FileFlag] -> FilePath -> Archive () -- | Undo changes to a file in the archive (referenced by position index). unchangeFileIx :: Int -> Archive () -- | Undo global changes to zip archive (revert changes to the archive -- comment and global flags). unchangeArchive :: Archive () -- | Undo all changes in a zip archive. unchangeAll :: Archive () -- | Wrapper for operations with a file in the archive. fromFile is -- normally called from within an Archive action (see also -- withArchive). fromFile can be replaced with -- fileContents to read an entire file at once. fromFile :: [FileFlag] -> FilePath -> Entry a -> Archive a -- | Wrapper for operations with a file in the archive. File is referenced -- by index (position). fromFileIx is normally called from within -- an Archive action (see also withArchive). -- fromFileIx can be replaced with fileContentsIx to read -- an entire file at once. fromFileIx :: [FileFlag] -> Int -> Entry a -> Archive a -- | Read at most n bytes from the file. readBytes :: (Enum a) => Int -> Entry [a] -- | Skip n bytes from the open file. Note: this is not faster -- than reading. skipBytes :: Int -> Entry () -- | Read entire file contents. readContents :: (Enum a) => Entry [a] -- | Read entire file. Shortcut for readContents from within -- Archive monad. fileContents :: (Enum a) => [FileFlag] -> FilePath -> Archive [a] -- | Read entire file (referenced by position index). Shortcut for -- readContents from within Archive monad. fileContentsIx :: (Enum a) => [FileFlag] -> Int -> Archive [a] -- | Flags for opening an archive. data OpenFlag -- | Create an archive if it does not exist. CreateFlag :: OpenFlag -- | Error if the archive already exists. ExclFlag :: OpenFlag -- | Check archive's consistency and error on failure. CheckConsFlag :: OpenFlag -- | Flags for accessing files in the archive. Please consult -- libzip documentation about their use. data FileFlag -- | Ignore case on name lookup. FileNOCASE :: FileFlag -- | Ignore directory component. FileNODIR :: FileFlag -- | Read the compressed data. FileCOMPRESSED :: FileFlag -- | Read the original data, ignore changes. FileUNCHANGED :: FileFlag -- | Force recompression of data. FileRECOMPRESS :: FileFlag -- | Compression methods. data ZipCompMethod -- | Better of deflate or store. CompDEFAULT :: ZipCompMethod -- | Stored (uncompressed). CompSTORE :: ZipCompMethod -- | Shrunk. CompSHRINK :: ZipCompMethod -- | Reduced with factor 1 CompREDUCE_1 :: ZipCompMethod -- | Reduced with factor 2 CompREDUCE_2 :: ZipCompMethod -- | Reduced with factor 3 CompREDUCE_3 :: ZipCompMethod -- | Reduced with factor 4 CompREDUCE_4 :: ZipCompMethod -- | Imploded. CompIMPLODE :: ZipCompMethod -- | Deflated. CompDEFLATE :: ZipCompMethod -- | Deflate64. CompDEFLATE64 :: ZipCompMethod -- | PKWARE imploding. CompPKWARE_IMPLODE :: ZipCompMethod -- | Compressed using BZIP2 algorithm. CompBZIP2 :: ZipCompMethod -- | LZMA (EFS) CompLZMA :: ZipCompMethod -- | Compressed using IBM TERSE (new). CompTERSE :: ZipCompMethod -- | IBM LZ77 z Architecture (PFS). CompLZ77 :: ZipCompMethod -- | WavPack compressed data. CompWAVPACK :: ZipCompMethod -- | PPMd version I, Rev 1. CompPPMD :: ZipCompMethod -- | Encryption methods. data ZipEncryptionMethod -- | Not encrypted. EncryptNONE :: ZipEncryptionMethod -- | Traditional PKWARE encryption. EncryptTRAD_PKWARE :: ZipEncryptionMethod -- | Unknown algorithm. EncryptUNKNOWN :: ZipEncryptionMethod -- | libzip error codes. data ZipError -- | No error. ErrOK :: ZipError -- | Multi-disk zip archives not supported. ErrMULTIDISK :: ZipError -- | Renaming temporary file failed. ErrRENAME :: ZipError -- | Closing zip archive failed. ErrCLOSE :: ZipError -- | Seek error. ErrSEEK :: ZipError -- | Read error. ErrREAD :: ZipError -- | Write error. ErrWRITE :: ZipError -- | CRC error. ErrCRC :: ZipError -- | Containing zip archive was closed. ErrZIPCLOSED :: ZipError -- | No such file. ErrNOENT :: ZipError -- | File already exists. ErrEXISTS :: ZipError -- | Can't open file. ErrOPEN :: ZipError -- | Failure to create temporary file. ErrTMPOPEN :: ZipError -- | Zlib error. ErrZLIB :: ZipError -- | Malloc error. ErrMEMORY :: ZipError -- | Entry has been changed. ErrCHANGED :: ZipError -- | Compression method not supported. ErrCOMPNOTSUPP :: ZipError -- | Premature EOF. ErrEOF :: ZipError -- | Invalid argument. ErrINVAL :: ZipError -- | Not a zip archive. ErrNOZIP :: ZipError -- | Internal error. ErrINTERNAL :: ZipError -- | Zip archive inconsistent. ErrINCONS :: ZipError -- | Can't remove file. ErrREMOVE :: ZipError -- | Entry has been deleted. ErrDELETED :: ZipError -- | Wrapper to catch library errors. catchZipError :: IO a -> (ZipError -> IO a) -> IO a lift :: (MonadTrans t) => forall m :: (* -> *) a. (Monad m) => m a -> t m a