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

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

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

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

-- | libzip archive global flags
data ArchiveFlag
ArchiveTORRENT :: ArchiveFlag
ArchiveRDONLY :: ArchiveFlag

-- | libzip flags for compression and encryption sources
data CodecFlag
CodecENCODE :: CodecFlag

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

-- | 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 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, 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.
--   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 :: [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 -> 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 :: Integer -> 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 -> 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
--   sourcePure. Data size should be known in advance
--   (srcSize). The function should support reading by chunks
--   (readSrc).
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 Just the size of data read,
--   the data themselves and the new state of the source, or
--   Nothing on error.
readSrc :: PureSource a st szt -> szt -> st -> Maybe (szt, [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, 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 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 :: Integer -> 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 :: 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. 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] -> Integer -> Entry a -> Archive a

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

-- | Skip n 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 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] -> 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

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

-- | Read encrypted data (implies FileCOMPRESSED).
FileENCRYPTED :: 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

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