-- 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.11.1

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. Constructors:
--   <tt>sourceBuffer</tt>, <tt>sourceFile</tt>, <tt>sourceZip</tt>,
--   <tt>sourcePure</tt>.
type ZipSource = Ptr C'zip_source

-- | File statistics expressed in native Haskell types.
data ZipStat
ZipStat :: Word64 -> String -> Integer -> Integer -> Integer -> UTCTime -> Word -> ZipCompMethod -> ZipEncryptionMethod -> Word32 -> ZipStat
zs'valid :: ZipStat -> Word64
zs'name :: ZipStat -> String
zs'index :: ZipStat -> Integer
zs'size :: ZipStat -> Integer
zs'comp_size :: ZipStat -> Integer
zs'mtime :: ZipStat -> UTCTime
zs'crc :: ZipStat -> Word
zs'comp_method :: ZipStat -> ZipCompMethod
zs'encryption_method :: ZipStat -> ZipEncryptionMethod
zs'flags :: ZipStat -> Word32

-- | 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

-- | If archive exists, ignore its current content.
TruncateFlag :: OpenFlag

-- | Flags for accessing files in the archive. Please consult
--   <tt>libzip</tt> 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

-- | Read encrypted data (implies FileCOMPRESSED).
FileENCRYPTED :: FileFlag

-- | Guess string encoding (default).
FileENC_GUESS :: FileFlag

-- | Get unmodified string.
FileENC_RAW :: FileFlag

-- | Follow specification strictly.
FileENC_STRICT :: FileFlag

-- | In local header.
FileLOCAL :: FileFlag

-- | In central directory.
FileCENTRAL :: FileFlag

-- | String is UTF-8 encoded.
FileENC_UTF_8 :: FileFlag

-- | String is CP437 encoded.
FileENC_CP437 :: FileFlag

-- | When adding files: if file name exists, overwrite.
FileOVERWRITE :: FileFlag

-- | <tt>libzip</tt> archive global flags
data ArchiveFlag
ArchiveTORRENT :: ArchiveFlag
ArchiveRDONLY :: ArchiveFlag

-- | <tt>libzip</tt> flags for compression and encryption sources
data CodecFlag
CodecENCODE :: CodecFlag
CodecDECODE :: CodecFlag

-- | <tt>libzip</tt> 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

-- | Encryption method not supported.
ErrENCRNOTSUPP :: ZipError

-- | Read-only archive.
ErrRDONLY :: ZipError

-- | No password provided.
ErrNOPASSWD :: ZipError

-- | Wrong password provided.
ErrWRONGPASSWD :: 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 OpenFlag
instance Eq OpenFlag
instance Show FileFlag
instance Eq FileFlag
instance Show ArchiveFlag
instance Eq ArchiveFlag
instance Show CodecFlag
instance Eq CodecFlag
instance Eq ZipError
instance Show ZipCompMethod
instance Eq ZipCompMethod
instance Show ZipEncryptionMethod
instance Eq ZipEncryptionMethod
instance Show ZipStat
instance Eq ZipStat
instance Enum ZipEncryptionMethod
instance Enum ZipCompMethod
instance Show ZipError
instance Exception ZipError
instance Enum ZipError
instance Enum CodecFlag
instance Enum ArchiveFlag
instance Enum FileFlag
instance Enum OpenFlag


-- | Monadic interface to <tt>libzip</tt>.
--   
--   Most of the operations on zip archive happen within <a>Archive</a>
--   monad (see <a>withArchive</a>). Partial reading of the files in the
--   archive may be performed from within <a>Entry</a> monad (see
--   <a>fromFile</a>). Both <a>Archive</a> and <a>Entry</a> are monad
--   transformers over <a>IO</a>, and allow for IO with single and double
--   <a>lift</a>ing respectingly.
--   
--   Note: LibZip does not handle text encodings. Even if its API accepts
--   <a>String</a>s (e.g. in <a>sourceBuffer</a>), character codes above
--   255 should not be used. The user is responsible of proper encoding the
--   text data.
--   
--   <i>Examples</i>
--   
--   List files in the zip archive:
--   
--   <pre>
--   import System.Environment (getArgs)
--   import Codec.Archive.LibZip
--   
--   main = do
--     (zipfile:_) &lt;- getArgs
--     files &lt;- withArchive [] zipfile $ fileNames []
--     mapM_ putStrLn files
--   </pre>
--   
--   Create a zip archive and a add file to the archive:
--   
--   <pre>
--   import System.Environment (getArgs)
--   import Codec.Archive.LibZip
--   
--   main = do
--     (zipfile:_) &lt;- getArgs
--     withArchive [CreateFlag] zipfile $ do
--        zs &lt;- sourceBuffer "Hello World!"
--        addFile "hello.txt" zs
--   </pre>
--   
--   Extract and print a file from the zip archive:
--   
--   <pre>
--   import System.Environment (getArgs)
--   import Codec.Archive.LibZip
--   
--   main = do
--     (zipfile:file:_) &lt;- getArgs
--     bytes &lt;- withArchive [] zipfile $ fileContents [] file
--     putStrLn bytes
--   </pre>
--   
--   See also an implementation of a simple zip archiver <tt>hzip.hs</tt>
--   in the <tt>examples/</tt> directory of the source distribution.
module Codec.Archive.LibZip

-- | Monadic computation with a zip archive. See <a>withArchive</a>.
type Archive a = StateT Zip IO a

-- | Monadic computation to read from open archive entries. See
--   <a>fromFile</a> and <a>fromFileIx</a>.
type Entry a = StateT (ZipFile, Integer, [FileFlag]) (StateT Zip IO) a

-- | File statistics expressed in native Haskell types.
data ZipStat
ZipStat :: Word64 -> String -> Integer -> Integer -> Integer -> UTCTime -> Word -> ZipCompMethod -> ZipEncryptionMethod -> Word32 -> ZipStat
zs'valid :: ZipStat -> Word64
zs'name :: ZipStat -> String
zs'index :: ZipStat -> Integer
zs'size :: ZipStat -> Integer
zs'comp_size :: ZipStat -> Integer
zs'mtime :: ZipStat -> UTCTime
zs'crc :: ZipStat -> Word
zs'comp_method :: ZipStat -> ZipCompMethod
zs'encryption_method :: ZipStat -> ZipEncryptionMethod
zs'flags :: ZipStat -> Word32

-- | Top-level wrapper for operations with an open archive.
--   <a>withArchive</a> opens and closes the file automatically. On error
--   it throws <a>ZipError</a>.
withArchive :: [OpenFlag] -> FilePath -> Archive a -> IO a

-- | Top-level wrapper for operations with an open encrypted archive.
--   <a>withEncryptedArchive</a> opens and closes the file automatically.
--   On error it throws <a>ZipError</a>.
withEncryptedArchive :: [OpenFlag] -> String -> FilePath -> Archive a -> IO a

-- | Get archive handler. Throw <a>ErrINVAL</a> if the archive is closed.
getZip :: Archive Zip

-- | Get the number of entries in the archive.
numFiles :: [FileFlag] -> Archive Integer

-- | Get name of an entry in the archive by its index.
fileName :: [FileFlag] -> Integer -> Archive FilePath

-- | Locate an entry (get its index) in the archive by its name.
nameLocate :: [FileFlag] -> FilePath -> Archive (Maybe Integer)

-- | 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 Integer

-- | Get size of a file in the archive (by index).
fileSizeIx :: [FileFlag] -> Integer -> Archive Integer

-- | 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] -> Integer -> Archive ZipStat

-- | Delete file from the archive.
deleteFile :: [FileFlag] -> FilePath -> Archive ()

-- | Delete file (referenced by position index) from the archive.
deleteFileIx :: Integer -> Archive ()

-- | Rename file in the archive.
renameFile :: [FileFlag] -> FilePath -> FilePath -> Archive ()

-- | Rename file (referenced by position index) in the archive.
renameFileIx :: Integer -> ByteString -> [FileFlag] -> Archive ()

-- | Add a file to the archive.
addFile :: FilePath -> ZipSource -> Archive Int
addFileWithFlags :: [FileFlag] -> ByteString -> ZipSource -> Archive Int

-- | Add a directory to the archive.
addDirectory :: FilePath -> Archive Int

-- | Add a directory to the archive.
addDirectoryWithFlags :: [FileFlag] -> ByteString -> Archive Int

-- | Replace a file in the archive.
replaceFile :: [FileFlag] -> FilePath -> ZipSource -> Archive ()

-- | Replace a file in the archive (referenced by position index).
replaceFileIx :: Integer -> ZipSource -> Archive ()

-- | Set compression method for a file in the archive.
setFileCompression :: [FileFlag] -> FilePath -> ZipCompMethod -> Archive ()

-- | Set compression method for a file in the archive.
setFileCompressionIx :: Integer -> ZipCompMethod -> Archive ()

-- | Create a data source. Note: input is converted to <tt>[Word8]</tt>
--   internally.
sourceBuffer :: Enum a => [a] -> Archive ZipSource

-- | Create a data source from a file.
sourceFile :: FilePath -> Integer -> Integer -> Archive ZipSource

-- | Create a data source from a file in the zip archive.
sourceZip :: [FileFlag] -> Zip -> Integer -> Integer -> Integer -> Archive ZipSource

-- | Wrapper for a user-provided pure function to be used with
--   <a>sourcePure</a>. Data size should be known in advance
--   (<a>srcSize</a>). The function should support reading by chunks
--   (<a>readSrc</a>).
data PureSource a st szt
PureSource :: st -> szt -> Maybe UTCTime -> (szt -> st -> Maybe (szt, [a], st)) -> PureSource a st szt

-- | Initial state of the source.
srcState :: PureSource a st szt -> st

-- | Total size of the data.
srcSize :: PureSource a st szt -> szt

-- | Modification time (current time if Nothing).
srcMTime :: PureSource a st szt -> Maybe UTCTime

-- | Read a chunk of the data, return <tt>Just</tt> the size of data read,
--   the data themselves and the new state of the source, or
--   <tt>Nothing</tt> on error.
readSrc :: PureSource a st szt -> szt -> st -> Maybe (szt, [a], st)

-- | Create a data source from a <a>PureSource</a>. Note: input of
--   <tt>[a]</tt> is converted to <tt>[Word8]</tt> internally.
sourcePure :: (Enum a, Storable a, Storable st, Integral szt) => PureSource a st szt -> 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] -> Integer -> Archive (Maybe ByteString)

-- | 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 :: Integer -> ByteString -> [FileFlag] -> 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 :: Integer -> 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 :: Integer -> 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. <a>fromFile</a> is
--   normally called from within an <a>Archive</a> action (see also
--   <a>withArchive</a>). <a>fromFile</a> can be replaced with
--   <a>fileContents</a> 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). <a>fromFileIx</a> is normally called from within
--   an <a>Archive</a> action (see also <a>withArchive</a>).
--   <a>fromFileIx</a> can be replaced with <a>fileContentsIx</a> to read
--   an entire file at once.
fromFileIx :: [FileFlag] -> Integer -> Entry a -> Archive a

-- | Read at most <tt>n</tt> bytes from the file.
readBytes :: Enum a => Integer -> Entry [a]

-- | Skip <tt>n</tt> bytes from the open file. Note: this is not faster
--   than reading.
skipBytes :: Integer -> Entry ()

-- | Read entire file contents.
readContents :: Enum a => Entry [a]

-- | Read entire file. Shortcut for <a>readContents</a> from within
--   <a>Archive</a> monad.
fileContents :: Enum a => [FileFlag] -> FilePath -> Archive [a]

-- | Read entire file (referenced by position index). Shortcut for
--   <a>readContents</a> from within <a>Archive</a> monad.
fileContentsIx :: Enum a => [FileFlag] -> Integer -> 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

-- | If archive exists, ignore its current content.
TruncateFlag :: OpenFlag

-- | Flags for accessing files in the archive. Please consult
--   <tt>libzip</tt> 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

-- | Read encrypted data (implies FileCOMPRESSED).
FileENCRYPTED :: FileFlag

-- | Guess string encoding (default).
FileENC_GUESS :: FileFlag

-- | Get unmodified string.
FileENC_RAW :: FileFlag

-- | Follow specification strictly.
FileENC_STRICT :: FileFlag

-- | In local header.
FileLOCAL :: FileFlag

-- | In central directory.
FileCENTRAL :: FileFlag

-- | String is UTF-8 encoded.
FileENC_UTF_8 :: FileFlag

-- | String is CP437 encoded.
FileENC_CP437 :: FileFlag

-- | When adding files: if file name exists, overwrite.
FileOVERWRITE :: 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

-- | <tt>libzip</tt> 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

-- | Encryption method not supported.
ErrENCRNOTSUPP :: ZipError

-- | Read-only archive.
ErrRDONLY :: ZipError

-- | No password provided.
ErrNOPASSWD :: ZipError

-- | Wrong password provided.
ErrWRONGPASSWD :: 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
