{-# LANGUAGE DeriveDataTypeable#-}

module Codec.Archive.LibZip.Types
    ( Zip
    , ZipFile
    , ZipSource
    , ZipStat(..)
    , toZipStat
    , OpenFlag(..)
    , FileFlag(..)
    , ArchiveFlag(..)
    , ZipError(..)
    , ZipCompMethod(..)
    , ZipEncryptionMethod(..)
    , combine
    ) where

import Data.Bits ((.|.))
import Data.Time (UTCTime)
import Data.Time.Clock.POSIX (posixSecondsToUTCTime)
import Data.Typeable (Typeable)
import Data.Word (Word32, Word64)
import Foreign.C.String (peekCString)
import Foreign.C.Types ()
import Foreign.Ptr (Ptr, nullPtr)
import qualified Control.Exception as E

import Bindings.LibZip

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

-- |  File statistics expressed in native Haskell types.
data ZipStat = ZipStat {
      ZipStat -> Word64
zs'valid :: Word64
    , ZipStat -> String
zs'name :: String
    , ZipStat -> Integer
zs'index :: Integer
    , ZipStat -> Integer
zs'size :: Integer
    , ZipStat -> Integer
zs'comp_size :: Integer
    , ZipStat -> UTCTime
zs'mtime :: UTCTime
    , ZipStat -> Word
zs'crc :: Word
    , ZipStat -> ZipCompMethod
zs'comp_method :: ZipCompMethod
    , ZipStat -> ZipEncryptionMethod
zs'encryption_method :: ZipEncryptionMethod
    , ZipStat -> Word32
zs'flags :: Word32
    } deriving (Int -> ZipStat -> ShowS
[ZipStat] -> ShowS
ZipStat -> String
(Int -> ZipStat -> ShowS)
-> (ZipStat -> String) -> ([ZipStat] -> ShowS) -> Show ZipStat
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ZipStat] -> ShowS
$cshowList :: [ZipStat] -> ShowS
show :: ZipStat -> String
$cshow :: ZipStat -> String
showsPrec :: Int -> ZipStat -> ShowS
$cshowsPrec :: Int -> ZipStat -> ShowS
Show, ZipStat -> ZipStat -> Bool
(ZipStat -> ZipStat -> Bool)
-> (ZipStat -> ZipStat -> Bool) -> Eq ZipStat
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ZipStat -> ZipStat -> Bool
$c/= :: ZipStat -> ZipStat -> Bool
== :: ZipStat -> ZipStat -> Bool
$c== :: ZipStat -> ZipStat -> Bool
Eq)

-- | Convert marshalled stat record.
toZipStat :: C'zip_stat -> IO ZipStat
toZipStat :: C'zip_stat -> IO ZipStat
toZipStat C'zip_stat
s = do
    let valid :: Word64
valid = CULLong -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CULLong -> Word64) -> CULLong -> Word64
forall a b. (a -> b) -> a -> b
$ C'zip_stat -> CULLong
c'zip_stat'valid C'zip_stat
s
    let np :: Ptr CChar
np = C'zip_stat -> Ptr CChar
c'zip_stat'name C'zip_stat
s
    String
name <- if (Ptr CChar
np Ptr CChar -> Ptr CChar -> Bool
forall a. Eq a => a -> a -> Bool
/= Ptr CChar
forall a. Ptr a
nullPtr) then Ptr CChar -> IO String
peekCString Ptr CChar
np else String -> IO String
forall (m :: * -> *) a. Monad m => a -> m a
return String
""
    let idx :: Integer
idx = CULLong -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CULLong -> Integer) -> CULLong -> Integer
forall a b. (a -> b) -> a -> b
$ C'zip_stat -> CULLong
c'zip_stat'index C'zip_stat
s
    let crc :: Word
crc = CUInt -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CUInt -> Word) -> CUInt -> Word
forall a b. (a -> b) -> a -> b
$ C'zip_stat -> CUInt
c'zip_stat'crc C'zip_stat
s
    let mtime :: UTCTime
mtime = POSIXTime -> UTCTime
posixSecondsToUTCTime (POSIXTime -> UTCTime) -> (CTime -> POSIXTime) -> CTime -> UTCTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CTime -> POSIXTime
forall a b. (Real a, Fractional b) => a -> b
realToFrac (CTime -> UTCTime) -> CTime -> UTCTime
forall a b. (a -> b) -> a -> b
$ C'zip_stat -> CTime
c'zip_stat'mtime C'zip_stat
s
    let size :: Integer
size = CULLong -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CULLong -> Integer) -> CULLong -> Integer
forall a b. (a -> b) -> a -> b
$ C'zip_stat -> CULLong
c'zip_stat'size C'zip_stat
s
    let comp_size :: Integer
comp_size = CULLong -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CULLong -> Integer) -> CULLong -> Integer
forall a b. (a -> b) -> a -> b
$ C'zip_stat -> CULLong
c'zip_stat'comp_size C'zip_stat
s
    let comp_meth :: ZipCompMethod
comp_meth = Int -> ZipCompMethod
forall a. Enum a => Int -> a
toEnum (Int -> ZipCompMethod)
-> (CUShort -> Int) -> CUShort -> ZipCompMethod
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CUShort -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CUShort -> ZipCompMethod) -> CUShort -> ZipCompMethod
forall a b. (a -> b) -> a -> b
$ C'zip_stat -> CUShort
c'zip_stat'comp_method C'zip_stat
s
    let enc_meth :: ZipEncryptionMethod
enc_meth = Int -> ZipEncryptionMethod
forall a. Enum a => Int -> a
toEnum (Int -> ZipEncryptionMethod)
-> (CUShort -> Int) -> CUShort -> ZipEncryptionMethod
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CUShort -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CUShort -> ZipEncryptionMethod) -> CUShort -> ZipEncryptionMethod
forall a b. (a -> b) -> a -> b
$ C'zip_stat -> CUShort
c'zip_stat'encryption_method C'zip_stat
s
    let flags :: Word32
flags =  Int -> Word32
forall a. Enum a => Int -> a
toEnum (Int -> Word32) -> (CUInt -> Int) -> CUInt -> Word32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CUInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CUInt -> Word32) -> CUInt -> Word32
forall a b. (a -> b) -> a -> b
$ C'zip_stat -> CUInt
c'zip_stat'flags C'zip_stat
s
    ZipStat -> IO ZipStat
forall (m :: * -> *) a. Monad m => a -> m a
return (ZipStat -> IO ZipStat) -> ZipStat -> IO ZipStat
forall a b. (a -> b) -> a -> b
$ Word64
-> String
-> Integer
-> Integer
-> Integer
-> UTCTime
-> Word
-> ZipCompMethod
-> ZipEncryptionMethod
-> Word32
-> ZipStat
ZipStat Word64
valid String
name Integer
idx Integer
size Integer
comp_size UTCTime
mtime Word
crc
             ZipCompMethod
comp_meth ZipEncryptionMethod
enc_meth Word32
flags


-- | Flags for opening an archive.
data OpenFlag
  = CreateFlag      -- ^ Create an archive if it does not exist.
  | ExclFlag        -- ^ Error if the archive already exists.
  | CheckConsFlag   -- ^ Check archive's consistency and error on failure.
  | TruncateFlag    -- ^ If archive exists, ignore its current content.
  deriving (Int -> OpenFlag -> ShowS
[OpenFlag] -> ShowS
OpenFlag -> String
(Int -> OpenFlag -> ShowS)
-> (OpenFlag -> String) -> ([OpenFlag] -> ShowS) -> Show OpenFlag
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OpenFlag] -> ShowS
$cshowList :: [OpenFlag] -> ShowS
show :: OpenFlag -> String
$cshow :: OpenFlag -> String
showsPrec :: Int -> OpenFlag -> ShowS
$cshowsPrec :: Int -> OpenFlag -> ShowS
Show,OpenFlag -> OpenFlag -> Bool
(OpenFlag -> OpenFlag -> Bool)
-> (OpenFlag -> OpenFlag -> Bool) -> Eq OpenFlag
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OpenFlag -> OpenFlag -> Bool
$c/= :: OpenFlag -> OpenFlag -> Bool
== :: OpenFlag -> OpenFlag -> Bool
$c== :: OpenFlag -> OpenFlag -> Bool
Eq)

instance Enum OpenFlag where
  fromEnum :: OpenFlag -> Int
fromEnum OpenFlag
CheckConsFlag = Int
forall a. Num a => a
c'ZIP_CHECKCONS
  fromEnum OpenFlag
CreateFlag = Int
forall a. Num a => a
c'ZIP_CREATE
  fromEnum OpenFlag
ExclFlag = Int
forall a. Num a => a
c'ZIP_EXCL
  fromEnum OpenFlag
TruncateFlag = Int
forall a. Num a => a
c'ZIP_TRUNCATE
  toEnum :: Int -> OpenFlag
toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_CHECKCONS = OpenFlag
CheckConsFlag
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_CREATE = OpenFlag
CreateFlag
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_EXCL = OpenFlag
ExclFlag
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_TRUNCATE = OpenFlag
TruncateFlag
  toEnum Int
_ = OpenFlag
forall a. HasCallStack => a
undefined

-- | Flags for accessing files in the archive.
-- Please consult @libzip@ documentation about their use.
data FileFlag
  = FileNOCASE      -- ^ Ignore case on name lookup.
  | FileNODIR       -- ^ Ignore directory component.
  | FileCOMPRESSED  -- ^ Read the compressed data.
  | FileUNCHANGED   -- ^ Read the original data, ignore changes.
  | FileRECOMPRESS  -- ^ Force recompression of data.
  | FileENCRYPTED   -- ^ Read encrypted data (implies FileCOMPRESSED).
  | FileENC_GUESS   -- ^ Guess string encoding (default).
  | FileENC_RAW     -- ^ Get unmodified string.
  | FileENC_STRICT  -- ^ Follow specification strictly.
  | FileLOCAL       -- ^ In local header.
  | FileCENTRAL     -- ^ In central directory.
  | FileENC_UTF_8   -- ^ String is UTF-8 encoded.
  | FileENC_CP437   -- ^ String is CP437 encoded.
  | FileOVERWRITE   -- ^ When adding files: if file name exists, overwrite.
  deriving (Int -> FileFlag -> ShowS
[FileFlag] -> ShowS
FileFlag -> String
(Int -> FileFlag -> ShowS)
-> (FileFlag -> String) -> ([FileFlag] -> ShowS) -> Show FileFlag
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FileFlag] -> ShowS
$cshowList :: [FileFlag] -> ShowS
show :: FileFlag -> String
$cshow :: FileFlag -> String
showsPrec :: Int -> FileFlag -> ShowS
$cshowsPrec :: Int -> FileFlag -> ShowS
Show,FileFlag -> FileFlag -> Bool
(FileFlag -> FileFlag -> Bool)
-> (FileFlag -> FileFlag -> Bool) -> Eq FileFlag
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FileFlag -> FileFlag -> Bool
$c/= :: FileFlag -> FileFlag -> Bool
== :: FileFlag -> FileFlag -> Bool
$c== :: FileFlag -> FileFlag -> Bool
Eq)

instance Enum FileFlag where
  fromEnum :: FileFlag -> Int
fromEnum FileFlag
FileCOMPRESSED = Int
forall a. Num a => a
c'ZIP_FL_COMPRESSED
  fromEnum FileFlag
FileNOCASE = Int
forall a. Num a => a
c'ZIP_FL_NOCASE
  fromEnum FileFlag
FileNODIR = Int
forall a. Num a => a
c'ZIP_FL_NODIR
  fromEnum FileFlag
FileRECOMPRESS = Int
forall a. Num a => a
c'ZIP_FL_RECOMPRESS
  fromEnum FileFlag
FileUNCHANGED = Int
forall a. Num a => a
c'ZIP_FL_UNCHANGED
  fromEnum FileFlag
FileENCRYPTED = Int
forall a. Num a => a
c'ZIP_FL_ENCRYPTED
  fromEnum FileFlag
FileENC_GUESS = Int
forall a. Num a => a
c'ZIP_FL_ENC_GUESS
  fromEnum FileFlag
FileENC_RAW = Int
forall a. Num a => a
c'ZIP_FL_ENC_RAW
  fromEnum FileFlag
FileENC_STRICT = Int
forall a. Num a => a
c'ZIP_FL_ENC_STRICT
  fromEnum FileFlag
FileLOCAL = Int
forall a. Num a => a
c'ZIP_FL_LOCAL
  fromEnum FileFlag
FileCENTRAL = Int
forall a. Num a => a
c'ZIP_FL_CENTRAL
  fromEnum FileFlag
FileENC_UTF_8 = Int
forall a. Num a => a
c'ZIP_FL_ENC_UTF_8
  fromEnum FileFlag
FileENC_CP437 = Int
forall a. Num a => a
c'ZIP_FL_ENC_CP437
  fromEnum FileFlag
FileOVERWRITE = Int
forall a. Num a => a
c'ZIP_FL_OVERWRITE
  toEnum :: Int -> FileFlag
toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_FL_COMPRESSED = FileFlag
FileCOMPRESSED
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_FL_NOCASE = FileFlag
FileNOCASE
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_FL_NODIR = FileFlag
FileNODIR
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_FL_RECOMPRESS = FileFlag
FileRECOMPRESS
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_FL_UNCHANGED = FileFlag
FileUNCHANGED
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_FL_ENCRYPTED = FileFlag
FileENCRYPTED
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_FL_ENC_GUESS = FileFlag
FileENC_GUESS
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_FL_ENC_RAW = FileFlag
FileENC_RAW
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_FL_ENC_STRICT = FileFlag
FileENC_STRICT
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_FL_LOCAL = FileFlag
FileLOCAL
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_FL_CENTRAL = FileFlag
FileCENTRAL
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_FL_ENC_UTF_8 = FileFlag
FileENC_UTF_8
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_FL_ENC_CP437 = FileFlag
FileENC_CP437
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_FL_OVERWRITE = FileFlag
FileOVERWRITE
  toEnum Int
_ = FileFlag
forall a. HasCallStack => a
undefined


-- | @libzip@ archive global flags
data ArchiveFlag
    = ArchiveRDONLY
    deriving (Int -> ArchiveFlag -> ShowS
[ArchiveFlag] -> ShowS
ArchiveFlag -> String
(Int -> ArchiveFlag -> ShowS)
-> (ArchiveFlag -> String)
-> ([ArchiveFlag] -> ShowS)
-> Show ArchiveFlag
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ArchiveFlag] -> ShowS
$cshowList :: [ArchiveFlag] -> ShowS
show :: ArchiveFlag -> String
$cshow :: ArchiveFlag -> String
showsPrec :: Int -> ArchiveFlag -> ShowS
$cshowsPrec :: Int -> ArchiveFlag -> ShowS
Show, ArchiveFlag -> ArchiveFlag -> Bool
(ArchiveFlag -> ArchiveFlag -> Bool)
-> (ArchiveFlag -> ArchiveFlag -> Bool) -> Eq ArchiveFlag
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ArchiveFlag -> ArchiveFlag -> Bool
$c/= :: ArchiveFlag -> ArchiveFlag -> Bool
== :: ArchiveFlag -> ArchiveFlag -> Bool
$c== :: ArchiveFlag -> ArchiveFlag -> Bool
Eq)

instance Enum ArchiveFlag where
    fromEnum :: ArchiveFlag -> Int
fromEnum ArchiveFlag
ArchiveRDONLY = Int
forall a. Num a => a
c'ZIP_AFL_RDONLY
    toEnum :: Int -> ArchiveFlag
toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_AFL_RDONLY = ArchiveFlag
ArchiveRDONLY
    toEnum Int
_ = ArchiveFlag
forall a. HasCallStack => a
undefined


-- | @libzip@ error codes.
data ZipError
  = ErrOK             -- ^ No error.
  | ErrMULTIDISK      -- ^ Multi-disk zip archives not supported.
  | ErrRENAME         -- ^ Renaming temporary file failed.
  | ErrCLOSE          -- ^ Closing zip archive failed.
  | ErrSEEK           -- ^ Seek error.
  | ErrREAD           -- ^ Read error.
  | ErrWRITE          -- ^ Write error.
  | ErrCRC            -- ^ CRC error.
  | ErrZIPCLOSED      -- ^ Containing zip archive was closed.
  | ErrNOENT          -- ^ No such file.
  | ErrEXISTS         -- ^ File already exists.
  | ErrOPEN           -- ^ Can't open file.
  | ErrTMPOPEN        -- ^ Failure to create temporary file.
  | ErrZLIB           -- ^ Zlib error.
  | ErrMEMORY         -- ^ Malloc error.
  | ErrCHANGED        -- ^ Entry has been changed.
  | ErrCOMPNOTSUPP    -- ^ Compression method not supported.
  | ErrEOF            -- ^ Premature EOF.
  | ErrINVAL          -- ^ Invalid argument.
  | ErrNOZIP          -- ^ Not a zip archive.
  | ErrINTERNAL       -- ^ Internal error.
  | ErrINCONS         -- ^ Zip archive inconsistent.
  | ErrREMOVE         -- ^ Can't remove file.
  | ErrDELETED        -- ^ Entry has been deleted.
  | ErrENCRNOTSUPP    -- ^ Encryption method not supported.
  | ErrRDONLY         -- ^ Read-only archive.
  | ErrNOPASSWD       -- ^ No password provided.
  | ErrWRONGPASSWD    -- ^ Wrong password provided.
  deriving (ZipError -> ZipError -> Bool
(ZipError -> ZipError -> Bool)
-> (ZipError -> ZipError -> Bool) -> Eq ZipError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ZipError -> ZipError -> Bool
$c/= :: ZipError -> ZipError -> Bool
== :: ZipError -> ZipError -> Bool
$c== :: ZipError -> ZipError -> Bool
Eq, Typeable)

instance Enum ZipError where
  fromEnum :: ZipError -> Int
fromEnum ZipError
ErrCHANGED = Int
forall a. Num a => a
c'ZIP_ER_CHANGED
  fromEnum ZipError
ErrCLOSE = Int
forall a. Num a => a
c'ZIP_ER_CLOSE
  fromEnum ZipError
ErrCOMPNOTSUPP = Int
forall a. Num a => a
c'ZIP_ER_COMPNOTSUPP
  fromEnum ZipError
ErrCRC = Int
forall a. Num a => a
c'ZIP_ER_CRC
  fromEnum ZipError
ErrDELETED = Int
forall a. Num a => a
c'ZIP_ER_DELETED
  fromEnum ZipError
ErrEOF = Int
forall a. Num a => a
c'ZIP_ER_EOF
  fromEnum ZipError
ErrEXISTS = Int
forall a. Num a => a
c'ZIP_ER_EXISTS
  fromEnum ZipError
ErrINCONS = Int
forall a. Num a => a
c'ZIP_ER_INCONS
  fromEnum ZipError
ErrINTERNAL = Int
forall a. Num a => a
c'ZIP_ER_INTERNAL
  fromEnum ZipError
ErrINVAL = Int
forall a. Num a => a
c'ZIP_ER_INVAL
  fromEnum ZipError
ErrMEMORY = Int
forall a. Num a => a
c'ZIP_ER_MEMORY
  fromEnum ZipError
ErrMULTIDISK = Int
forall a. Num a => a
c'ZIP_ER_MULTIDISK
  fromEnum ZipError
ErrNOENT = Int
forall a. Num a => a
c'ZIP_ER_NOENT
  fromEnum ZipError
ErrNOZIP = Int
forall a. Num a => a
c'ZIP_ER_NOZIP
  fromEnum ZipError
ErrOK = Int
forall a. Num a => a
c'ZIP_ER_OK
  fromEnum ZipError
ErrOPEN = Int
forall a. Num a => a
c'ZIP_ER_OPEN
  fromEnum ZipError
ErrREAD = Int
forall a. Num a => a
c'ZIP_ER_READ
  fromEnum ZipError
ErrREMOVE = Int
forall a. Num a => a
c'ZIP_ER_REMOVE
  fromEnum ZipError
ErrRENAME = Int
forall a. Num a => a
c'ZIP_ER_RENAME
  fromEnum ZipError
ErrSEEK = Int
forall a. Num a => a
c'ZIP_ER_SEEK
  fromEnum ZipError
ErrTMPOPEN = Int
forall a. Num a => a
c'ZIP_ER_TMPOPEN
  fromEnum ZipError
ErrWRITE = Int
forall a. Num a => a
c'ZIP_ER_WRITE
  fromEnum ZipError
ErrZIPCLOSED = Int
forall a. Num a => a
c'ZIP_ER_ZIPCLOSED
  fromEnum ZipError
ErrZLIB = Int
forall a. Num a => a
c'ZIP_ER_ZLIB
  fromEnum ZipError
ErrENCRNOTSUPP = Int
forall a. Num a => a
c'ZIP_ER_ENCRNOTSUPP
  fromEnum ZipError
ErrRDONLY = Int
forall a. Num a => a
c'ZIP_ER_RDONLY
  fromEnum ZipError
ErrNOPASSWD = Int
forall a. Num a => a
c'ZIP_ER_NOPASSWD
  fromEnum ZipError
ErrWRONGPASSWD = Int
forall a. Num a => a
c'ZIP_ER_WRONGPASSWD
  toEnum :: Int -> ZipError
toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_ER_CHANGED = ZipError
ErrCHANGED
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_ER_CLOSE = ZipError
ErrCLOSE
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_ER_COMPNOTSUPP = ZipError
ErrCOMPNOTSUPP
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_ER_CRC = ZipError
ErrCRC
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_ER_DELETED = ZipError
ErrDELETED
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_ER_EOF = ZipError
ErrEOF
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_ER_EXISTS = ZipError
ErrEXISTS
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_ER_INCONS = ZipError
ErrINCONS
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_ER_INTERNAL = ZipError
ErrINTERNAL
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_ER_INVAL = ZipError
ErrINVAL
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_ER_MEMORY = ZipError
ErrMEMORY
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_ER_MULTIDISK = ZipError
ErrMULTIDISK
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_ER_NOENT = ZipError
ErrNOENT
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_ER_NOZIP = ZipError
ErrNOZIP
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_ER_OK = ZipError
ErrOK
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_ER_OPEN = ZipError
ErrOPEN
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_ER_READ = ZipError
ErrREAD
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_ER_REMOVE = ZipError
ErrREMOVE
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_ER_RENAME = ZipError
ErrRENAME
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_ER_SEEK = ZipError
ErrSEEK
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_ER_TMPOPEN = ZipError
ErrTMPOPEN
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_ER_WRITE = ZipError
ErrWRITE
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_ER_ZIPCLOSED = ZipError
ErrZIPCLOSED
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_ER_ZLIB = ZipError
ErrZLIB
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_ER_ENCRNOTSUPP = ZipError
ErrENCRNOTSUPP
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_ER_RDONLY = ZipError
ErrRDONLY
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_ER_NOPASSWD = ZipError
ErrNOPASSWD
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_ER_WRONGPASSWD = ZipError
ErrWRONGPASSWD
  toEnum Int
_ = ZipError
forall a. HasCallStack => a
undefined

instance E.Exception ZipError

instance Show ZipError where
  show :: ZipError -> String
show ZipError
ErrOK             =  String
"No error"
  show ZipError
ErrMULTIDISK      =  String
"Multi-disk zip archives not supported"
  show ZipError
ErrRENAME         =  String
"Renaming temporary file failed"
  show ZipError
ErrCLOSE          =  String
"Closing zip archive failed"
  show ZipError
ErrSEEK           =  String
"Seek error"
  show ZipError
ErrREAD           =  String
"Read error"
  show ZipError
ErrWRITE          =  String
"Write error"
  show ZipError
ErrCRC            =  String
"CRC error"
  show ZipError
ErrZIPCLOSED      =  String
"Containing zip archive was closed"
  show ZipError
ErrNOENT          =  String
"No such file"
  show ZipError
ErrEXISTS         =  String
"File already exists"
  show ZipError
ErrOPEN           =  String
"Can't open file"
  show ZipError
ErrTMPOPEN        =  String
"Failure to create temporary file"
  show ZipError
ErrZLIB           =  String
"Zlib error"
  show ZipError
ErrMEMORY         =  String
"Malloc failure"
  show ZipError
ErrCHANGED        =  String
"Entry has been changed"
  show ZipError
ErrCOMPNOTSUPP    =  String
"Compression method not supported"
  show ZipError
ErrEOF            =  String
"Premature EOF"
  show ZipError
ErrINVAL          =  String
"Invalid argument"
  show ZipError
ErrNOZIP          =  String
"Not a zip archive"
  show ZipError
ErrINTERNAL       =  String
"Internal error"
  show ZipError
ErrINCONS         =  String
"Zip archive inconsistent"
  show ZipError
ErrREMOVE         =  String
"Can't remove file"
  show ZipError
ErrDELETED        =  String
"Entry has been deleted"
  show ZipError
ErrENCRNOTSUPP    =  String
"Encryption method not supported"
  show ZipError
ErrRDONLY         =  String
"Read-only archive"
  show ZipError
ErrNOPASSWD       =  String
"No password provided"
  show ZipError
ErrWRONGPASSWD    =  String
"Wrong password provided"

-- | Compression methods.
data ZipCompMethod
  = CompDEFAULT         -- ^ Better of deflate or store.
  | CompSTORE           -- ^ Stored (uncompressed).
  | CompSHRINK          -- ^ Shrunk.
  | CompREDUCE_1        -- ^ Reduced with factor 1
  | CompREDUCE_2        -- ^ Reduced with factor 2
  | CompREDUCE_3        -- ^ Reduced with factor 3
  | CompREDUCE_4        -- ^ Reduced with factor 4
  | CompIMPLODE         -- ^ Imploded.
  | CompDEFLATE         -- ^ Deflated.
  | CompDEFLATE64       -- ^ Deflate64.
  | CompPKWARE_IMPLODE  -- ^ PKWARE imploding.
  | CompBZIP2           -- ^ Compressed using BZIP2 algorithm.
  | CompLZMA            -- ^ LZMA (EFS)
  | CompTERSE           -- ^ Compressed using IBM TERSE (new).
  | CompLZ77            -- ^ IBM LZ77 z Architecture (PFS).
  | CompWAVPACK         -- ^ WavPack compressed data.
  | CompPPMD            -- ^ PPMd version I, Rev 1.
  deriving (Int -> ZipCompMethod -> ShowS
[ZipCompMethod] -> ShowS
ZipCompMethod -> String
(Int -> ZipCompMethod -> ShowS)
-> (ZipCompMethod -> String)
-> ([ZipCompMethod] -> ShowS)
-> Show ZipCompMethod
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ZipCompMethod] -> ShowS
$cshowList :: [ZipCompMethod] -> ShowS
show :: ZipCompMethod -> String
$cshow :: ZipCompMethod -> String
showsPrec :: Int -> ZipCompMethod -> ShowS
$cshowsPrec :: Int -> ZipCompMethod -> ShowS
Show, ZipCompMethod -> ZipCompMethod -> Bool
(ZipCompMethod -> ZipCompMethod -> Bool)
-> (ZipCompMethod -> ZipCompMethod -> Bool) -> Eq ZipCompMethod
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ZipCompMethod -> ZipCompMethod -> Bool
$c/= :: ZipCompMethod -> ZipCompMethod -> Bool
== :: ZipCompMethod -> ZipCompMethod -> Bool
$c== :: ZipCompMethod -> ZipCompMethod -> Bool
Eq)

instance Enum ZipCompMethod where
  fromEnum :: ZipCompMethod -> Int
fromEnum ZipCompMethod
CompDEFAULT = Int
forall a. Num a => a
c'ZIP_CM_DEFAULT
  fromEnum ZipCompMethod
CompSTORE = Int
forall a. Num a => a
c'ZIP_CM_STORE
  fromEnum ZipCompMethod
CompSHRINK = Int
forall a. Num a => a
c'ZIP_CM_SHRINK
  fromEnum ZipCompMethod
CompREDUCE_1 = Int
forall a. Num a => a
c'ZIP_CM_REDUCE_1
  fromEnum ZipCompMethod
CompREDUCE_2 = Int
forall a. Num a => a
c'ZIP_CM_REDUCE_2
  fromEnum ZipCompMethod
CompREDUCE_3 = Int
forall a. Num a => a
c'ZIP_CM_REDUCE_3
  fromEnum ZipCompMethod
CompREDUCE_4 = Int
forall a. Num a => a
c'ZIP_CM_REDUCE_4
  fromEnum ZipCompMethod
CompIMPLODE = Int
forall a. Num a => a
c'ZIP_CM_IMPLODE
  fromEnum ZipCompMethod
CompDEFLATE = Int
forall a. Num a => a
c'ZIP_CM_DEFLATE
  fromEnum ZipCompMethod
CompDEFLATE64 = Int
forall a. Num a => a
c'ZIP_CM_DEFLATE64
  fromEnum ZipCompMethod
CompPKWARE_IMPLODE = Int
forall a. Num a => a
c'ZIP_CM_PKWARE_IMPLODE
  fromEnum ZipCompMethod
CompBZIP2 = Int
forall a. Num a => a
c'ZIP_CM_BZIP2
  fromEnum ZipCompMethod
CompLZMA = Int
forall a. Num a => a
c'ZIP_CM_LZMA
  fromEnum ZipCompMethod
CompTERSE = Int
forall a. Num a => a
c'ZIP_CM_TERSE
  fromEnum ZipCompMethod
CompLZ77 = Int
forall a. Num a => a
c'ZIP_CM_LZ77
  fromEnum ZipCompMethod
CompWAVPACK = Int
forall a. Num a => a
c'ZIP_CM_WAVPACK
  fromEnum ZipCompMethod
CompPPMD = Int
forall a. Num a => a
c'ZIP_CM_PPMD
  toEnum :: Int -> ZipCompMethod
toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_CM_DEFAULT = ZipCompMethod
CompDEFAULT
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_CM_STORE = ZipCompMethod
CompSTORE
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_CM_SHRINK = ZipCompMethod
CompSHRINK
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_CM_REDUCE_1 = ZipCompMethod
CompREDUCE_1
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_CM_REDUCE_2 = ZipCompMethod
CompREDUCE_2
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_CM_REDUCE_3 = ZipCompMethod
CompREDUCE_3
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_CM_REDUCE_4 = ZipCompMethod
CompREDUCE_4
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_CM_IMPLODE = ZipCompMethod
CompIMPLODE
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_CM_DEFLATE = ZipCompMethod
CompDEFLATE
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_CM_DEFLATE64 = ZipCompMethod
CompDEFLATE64
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_CM_PKWARE_IMPLODE = ZipCompMethod
CompPKWARE_IMPLODE
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_CM_BZIP2 = ZipCompMethod
CompBZIP2
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_CM_LZMA = ZipCompMethod
CompLZMA
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_CM_TERSE = ZipCompMethod
CompTERSE
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_CM_LZ77 = ZipCompMethod
CompLZ77
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_CM_WAVPACK = ZipCompMethod
CompWAVPACK
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_CM_PPMD = ZipCompMethod
CompPPMD
  toEnum Int
_ = ZipCompMethod
forall a. HasCallStack => a
undefined

-- | Encryption methods.
data ZipEncryptionMethod
  = EncryptNONE          -- ^ Not encrypted.
  | EncryptTRAD_PKWARE   -- ^ Traditional PKWARE encryption.
  | EncryptUNKNOWN       -- ^ Unknown algorithm.
  deriving (Int -> ZipEncryptionMethod -> ShowS
[ZipEncryptionMethod] -> ShowS
ZipEncryptionMethod -> String
(Int -> ZipEncryptionMethod -> ShowS)
-> (ZipEncryptionMethod -> String)
-> ([ZipEncryptionMethod] -> ShowS)
-> Show ZipEncryptionMethod
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ZipEncryptionMethod] -> ShowS
$cshowList :: [ZipEncryptionMethod] -> ShowS
show :: ZipEncryptionMethod -> String
$cshow :: ZipEncryptionMethod -> String
showsPrec :: Int -> ZipEncryptionMethod -> ShowS
$cshowsPrec :: Int -> ZipEncryptionMethod -> ShowS
Show,ZipEncryptionMethod -> ZipEncryptionMethod -> Bool
(ZipEncryptionMethod -> ZipEncryptionMethod -> Bool)
-> (ZipEncryptionMethod -> ZipEncryptionMethod -> Bool)
-> Eq ZipEncryptionMethod
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ZipEncryptionMethod -> ZipEncryptionMethod -> Bool
$c/= :: ZipEncryptionMethod -> ZipEncryptionMethod -> Bool
== :: ZipEncryptionMethod -> ZipEncryptionMethod -> Bool
$c== :: ZipEncryptionMethod -> ZipEncryptionMethod -> Bool
Eq)

instance Enum ZipEncryptionMethod where
  fromEnum :: ZipEncryptionMethod -> Int
fromEnum ZipEncryptionMethod
EncryptNONE = Int
forall a. Num a => a
c'ZIP_EM_NONE
  fromEnum ZipEncryptionMethod
EncryptTRAD_PKWARE = Int
forall a. Num a => a
c'ZIP_EM_TRAD_PKWARE
  fromEnum ZipEncryptionMethod
EncryptUNKNOWN = Int
forall a. Num a => a
c'ZIP_EM_UNKNOWN
  toEnum :: Int -> ZipEncryptionMethod
toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_EM_NONE = ZipEncryptionMethod
EncryptNONE
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_EM_TRAD_PKWARE = ZipEncryptionMethod
EncryptTRAD_PKWARE
  toEnum Int
x | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Num a => a
c'ZIP_EM_UNKNOWN = ZipEncryptionMethod
EncryptUNKNOWN
  toEnum Int
_ = ZipEncryptionMethod
forall a. HasCallStack => a
undefined

combine :: (Enum a, Num b) => [a] -> b
combine :: [a] -> b
combine [a]
fs = Int -> b
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> b) -> ([Int] -> Int) -> [Int] -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> Int -> Int) -> Int -> [Int] -> Int
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Int -> Int -> Int
forall a. Bits a => a -> a -> a
(.|.) Int
0 ([Int] -> b) -> [Int] -> b
forall a b. (a -> b) -> a -> b
$ (a -> Int) -> [a] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map a -> Int
forall a. Enum a => a -> Int
fromEnum [a]
fs