zip-2.2.1: Operations on zip archives

Copyright | © 2016–present Mark Karpov
License | BSD 3 clause
Maintainer | Mark Karpov <markkarpov92@gmail.com>
Stability | experimental
Portability | portable
Safe Haskell | None
Language | GHC2021

Codec.Archive.Zip.Internal.Type

Contents

- Entry selector
- Entry description
- Archive description
- Exceptions

Description

Types used by the package.

Synopsis

- data EntrySelector
- mkEntrySelector :: MonadThrow m => FilePath -> m EntrySelector
- unEntrySelector :: EntrySelector -> FilePath
- getEntryName :: EntrySelector -> Text
- newtype EntrySelectorException = InvalidEntrySelector FilePath
- data EntryDescription = EntryDescription {
  - edVersionMadeBy :: Version
  - edVersionNeeded :: Version
  - edCompression :: CompressionMethod
  - edModTime :: UTCTime
  - edCRC32 :: Word32
  - edCompressedSize :: Natural
  - edUncompressedSize :: Natural
  - edOffset :: Natural
  - edComment :: Maybe Text
  - edExtraField :: Map Word16 ByteString
  - edExternalFileAttrs :: Word32
  }
- data CompressionMethod
  - = Store
  - | Deflate
  - | BZip2
  - | Zstd
- data ArchiveDescription = ArchiveDescription {
  - adComment :: Maybe Text
  - adCDOffset :: Natural
  - adCDSize :: Natural
  }
- data ZipException
  - = EntryDoesNotExist FilePath EntrySelector
  - | UnsupportedCompressionMethod CompressionMethod
  - | ParsingFailed FilePath String

# Entry selector

data EntrySelector Source #

This data type serves for naming and selection of archive entries. It can be created only with the help of the smart constructor `mkEntrySelector`, and it's the only “key” that can be used to refer to files in the archive or to name new archive entries.

The abstraction is crucial for ensuring that created archives are portable across operating systems, file systems, and platforms. Since on some operating systems, file paths are case-insensitive, this selector is also case-insensitive. It makes sure that only relative paths are used to name files inside archive, as it's recommended in the specification. It also guarantees that forward slashes are used when the path is stored inside the archive for compatibility with Unix-like operating systems (as recommended in the specification). On the other hand, in can be rendered as an ordinary relative file path in OS-specific format when needed.

#### Instances

Instances details

Show EntrySelector Source # |
Instance details Defined in Codec.Archive.Zip.Internal.Type Methods showsPrec :: Int -> EntrySelector -> ShowS Source # show :: EntrySelector -> String Source # showList :: [EntrySelector] -> ShowS Source #
Eq EntrySelector Source # |
Instance details Defined in Codec.Archive.Zip.Internal.Type Methods (==) :: EntrySelector -> EntrySelector -> Bool Source # (/=) :: EntrySelector -> EntrySelector -> Bool Source #
Ord EntrySelector Source # |

Instance details

Defined in Codec.Archive.Zip.Internal.Type

Methods

compare :: EntrySelector -> EntrySelector -> Ordering Source #

(<) :: EntrySelector -> EntrySelector -> Bool Source #

(<=) :: EntrySelector -> EntrySelector -> Bool Source #

(>) :: EntrySelector -> EntrySelector -> Bool Source #

(>=) :: EntrySelector -> EntrySelector -> Bool Source #

max :: EntrySelector -> EntrySelector -> EntrySelector Source #

min :: EntrySelector -> EntrySelector -> EntrySelector Source #

mkEntrySelector :: MonadThrow m => FilePath -> m EntrySelector Source #

Create an `EntrySelector` from a `FilePath`. To avoid problems with distribution of the archive, characters that some operating systems do not expect in paths are not allowed.

Argument to `mkEntrySelector` should pass these checks:

- `isValid`
- `isValid`
- it is a relative path without slash at the end
- binary representations of normalized path should be not longer than 65535 bytes

This function can throw an `EntrySelectorException`.

unEntrySelector :: EntrySelector -> FilePath Source #

Restore a relative path from `EntrySelector`. Every `EntrySelector` corresponds to a `FilePath`.

getEntryName :: EntrySelector -> Text Source #

Get an entry name in the from that is suitable for writing to file header, given an `EntrySelector`.

newtype EntrySelectorException Source #

The problems you can have with an `EntrySelector`.

Constructors

InvalidEntrySelector FilePath | `EntrySelector` cannot be created from this path

#### Instances

Instances details

Exception EntrySelectorException Source # |
Instance details Defined in Codec.Archive.Zip.Internal.Type Methods toException :: EntrySelectorException -> SomeException Source # fromException :: SomeException -> Maybe EntrySelectorException Source # displayException :: EntrySelectorException -> String Source # backtraceDesired :: EntrySelectorException -> Bool Source #
Show EntrySelectorException Source # |
Instance details Defined in Codec.Archive.Zip.Internal.Type Methods showsPrec :: Int -> EntrySelectorException -> ShowS Source # show :: EntrySelectorException -> String Source # showList :: [EntrySelectorException] -> ShowS Source #
Eq EntrySelectorException Source # |
Instance details Defined in Codec.Archive.Zip.Internal.Type Methods (==) :: EntrySelectorException -> EntrySelectorException -> Bool Source # (/=) :: EntrySelectorException -> EntrySelectorException -> Bool Source #
Ord EntrySelectorException Source # |

Instance details

Defined in Codec.Archive.Zip.Internal.Type

Methods

compare :: EntrySelectorException -> EntrySelectorException -> Ordering Source #

(<) :: EntrySelectorException -> EntrySelectorException -> Bool Source #

(<=) :: EntrySelectorException -> EntrySelectorException -> Bool Source #

(>) :: EntrySelectorException -> EntrySelectorException -> Bool Source #

(>=) :: EntrySelectorException -> EntrySelectorException -> Bool Source #

max :: EntrySelectorException -> EntrySelectorException -> EntrySelectorException Source #

min :: EntrySelectorException -> EntrySelectorException -> EntrySelectorException Source #

# Entry description

data EntryDescription Source #

The information about archive entry that can be stored in a zip archive. It does not mirror local file header or central directory file header, but their binary representations can be built given this data structure and the archive contents.

Constructors

EntryDescription |

Fields

- edVersionMadeBy :: Version

  Version made by

- edVersionNeeded :: Version

  Version needed to extract

- edCompression :: CompressionMethod

  Compression method

- edModTime :: UTCTime

  Last modification date and time

- edCRC32 :: Word32

  CRC32 check sum

- edCompressedSize :: Natural

  Size of compressed entry

- edUncompressedSize :: Natural

  Size of uncompressed entry

- edOffset :: Natural

  Absolute offset of local file header

- edComment :: Maybe Text

  Entry comment

- edExtraField :: Map Word16 ByteString

  All extra fields found

- edExternalFileAttrs :: Word32

  External file attributes

  Since: 1.2.0

#### Instances

Instances details

Show EntryDescription Source # |
Instance details Defined in Codec.Archive.Zip.Internal.Type Methods showsPrec :: Int -> EntryDescription -> ShowS Source # show :: EntryDescription -> String Source # showList :: [EntryDescription] -> ShowS Source #
Eq EntryDescription Source # |
Instance details Defined in Codec.Archive.Zip.Internal.Type Methods (==) :: EntryDescription -> EntryDescription -> Bool Source # (/=) :: EntryDescription -> EntryDescription -> Bool Source #

data CompressionMethod Source #

The supported compression methods.

Constructors

Store | Store file uncompressed
Deflate | Deflate
BZip2 | Compressed using BZip2 algorithm
Zstd | Compressed using Zstandard algorithm Since: 1.6.0

#### Instances

Instances details

Data CompressionMethod Source # |

Instance details

Defined in Codec.Archive.Zip.Internal.Type

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> CompressionMethod -> c CompressionMethod Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c CompressionMethod Source #

toConstr :: CompressionMethod -> Constr Source #

dataTypeOf :: CompressionMethod -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c CompressionMethod) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c CompressionMethod) Source #

gmapT :: (forall b. Data b => b -> b) -> CompressionMethod -> CompressionMethod Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> CompressionMethod -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> CompressionMethod -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> CompressionMethod -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> CompressionMethod -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> CompressionMethod -> m CompressionMethod Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> CompressionMethod -> m CompressionMethod Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> CompressionMethod -> m CompressionMethod Source #

Bounded CompressionMethod Source # |
Instance details Defined in Codec.Archive.Zip.Internal.Type Methods minBound :: CompressionMethod Source # maxBound :: CompressionMethod Source #
Enum CompressionMethod Source # |

Instance details

Defined in Codec.Archive.Zip.Internal.Type

Methods

succ :: CompressionMethod -> CompressionMethod Source #

pred :: CompressionMethod -> CompressionMethod Source #

toEnum :: Int -> CompressionMethod Source #

fromEnum :: CompressionMethod -> Int Source #

enumFrom :: CompressionMethod -> [CompressionMethod] Source #

enumFromThen :: CompressionMethod -> CompressionMethod -> [CompressionMethod] Source #

enumFromTo :: CompressionMethod -> CompressionMethod -> [CompressionMethod] Source #

enumFromThenTo :: CompressionMethod -> CompressionMethod -> CompressionMethod -> [CompressionMethod] Source #

Read CompressionMethod Source # |
Instance details Defined in Codec.Archive.Zip.Internal.Type Methods readsPrec :: Int -> ReadS CompressionMethod Source # readList :: ReadS [CompressionMethod] Source # readPrec :: ReadPrec CompressionMethod Source # readListPrec :: ReadPrec [CompressionMethod] Source #
Show CompressionMethod Source # |
Instance details Defined in Codec.Archive.Zip.Internal.Type Methods showsPrec :: Int -> CompressionMethod -> ShowS Source # show :: CompressionMethod -> String Source # showList :: [CompressionMethod] -> ShowS Source #
Eq CompressionMethod Source # |
Instance details Defined in Codec.Archive.Zip.Internal.Type Methods (==) :: CompressionMethod -> CompressionMethod -> Bool Source # (/=) :: CompressionMethod -> CompressionMethod -> Bool Source #
Ord CompressionMethod Source # |

Instance details

Defined in Codec.Archive.Zip.Internal.Type

Methods

compare :: CompressionMethod -> CompressionMethod -> Ordering Source #

(<) :: CompressionMethod -> CompressionMethod -> Bool Source #

(<=) :: CompressionMethod -> CompressionMethod -> Bool Source #

(>) :: CompressionMethod -> CompressionMethod -> Bool Source #

(>=) :: CompressionMethod -> CompressionMethod -> Bool Source #

max :: CompressionMethod -> CompressionMethod -> CompressionMethod Source #

min :: CompressionMethod -> CompressionMethod -> CompressionMethod Source #

# Archive description

data ArchiveDescription Source #

The information about the archive as a whole.

Constructors

ArchiveDescription |

Fields

- adComment :: Maybe Text

  The comment of the entire archive

- adCDOffset :: Natural

  Absolute offset of the start of central directory

- adCDSize :: Natural

  The size of central directory record

#### Instances

Instances details

Data ArchiveDescription Source # |

Instance details

Defined in Codec.Archive.Zip.Internal.Type

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> ArchiveDescription -> c ArchiveDescription Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c ArchiveDescription Source #

toConstr :: ArchiveDescription -> Constr Source #

dataTypeOf :: ArchiveDescription -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c ArchiveDescription) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ArchiveDescription) Source #

gmapT :: (forall b. Data b => b -> b) -> ArchiveDescription -> ArchiveDescription Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ArchiveDescription -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ArchiveDescription -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> ArchiveDescription -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> ArchiveDescription -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> ArchiveDescription -> m ArchiveDescription Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> ArchiveDescription -> m ArchiveDescription Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> ArchiveDescription -> m ArchiveDescription Source #

Read ArchiveDescription Source # |
Instance details Defined in Codec.Archive.Zip.Internal.Type Methods readsPrec :: Int -> ReadS ArchiveDescription Source # readList :: ReadS [ArchiveDescription] Source # readPrec :: ReadPrec ArchiveDescription Source # readListPrec :: ReadPrec [ArchiveDescription] Source #
Show ArchiveDescription Source # |
Instance details Defined in Codec.Archive.Zip.Internal.Type Methods showsPrec :: Int -> ArchiveDescription -> ShowS Source # show :: ArchiveDescription -> String Source # showList :: [ArchiveDescription] -> ShowS Source #
Eq ArchiveDescription Source # |
Instance details Defined in Codec.Archive.Zip.Internal.Type Methods (==) :: ArchiveDescription -> ArchiveDescription -> Bool Source # (/=) :: ArchiveDescription -> ArchiveDescription -> Bool Source #
Ord ArchiveDescription Source # |

Instance details

Defined in Codec.Archive.Zip.Internal.Type

Methods

compare :: ArchiveDescription -> ArchiveDescription -> Ordering Source #

(<) :: ArchiveDescription -> ArchiveDescription -> Bool Source #

(<=) :: ArchiveDescription -> ArchiveDescription -> Bool Source #

(>) :: ArchiveDescription -> ArchiveDescription -> Bool Source #

(>=) :: ArchiveDescription -> ArchiveDescription -> Bool Source #

max :: ArchiveDescription -> ArchiveDescription -> ArchiveDescription Source #

min :: ArchiveDescription -> ArchiveDescription -> ArchiveDescription Source #

# Exceptions

data ZipException Source #

The bad things that can happen when you use the library.

Constructors

EntryDoesNotExist FilePath EntrySelector | Thrown when you try to get contents of non-existing entry
UnsupportedCompressionMethod CompressionMethod | Thrown when attempting to decompress an entry compressed with an unsupported compression method or the library is compiled without support for it. Since: 2.0.0
ParsingFailed FilePath String | Thrown when archive structure cannot be parsed.

#### Instances

Instances details

Exception ZipException Source # |
Instance details Defined in Codec.Archive.Zip.Internal.Type Methods toException :: ZipException -> SomeException Source # fromException :: SomeException -> Maybe ZipException Source # displayException :: ZipException -> String Source # backtraceDesired :: ZipException -> Bool Source #
Show ZipException Source # |
Instance details Defined in Codec.Archive.Zip.Internal.Type Methods showsPrec :: Int -> ZipException -> ShowS Source # show :: ZipException -> String Source # showList :: [ZipException] -> ShowS Source #
Eq ZipException Source # |
Instance details Defined in Codec.Archive.Zip.Internal.Type Methods (==) :: ZipException -> ZipException -> Bool Source # (/=) :: ZipException -> ZipException -> Bool Source #
Ord ZipException Source # |

Instance details

Defined in Codec.Archive.Zip.Internal.Type

Methods

compare :: ZipException -> ZipException -> Ordering Source #

(<) :: ZipException -> ZipException -> Bool Source #

(<=) :: ZipException -> ZipException -> Bool Source #

(>) :: ZipException -> ZipException -> Bool Source #

(>=) :: ZipException -> ZipException -> Bool Source #

max :: ZipException -> ZipException -> ZipException Source #

min :: ZipException -> ZipException -> ZipException Source #