zip-stream-0.2.2.0: ZIP archive streaming using conduits

Safe Haskell | Safe-Inferred
Language | Haskell2010

Codec.Archive.Zip.Conduit.Zip

Description

Stream the creation of a zip file, e.g., as it's being uploaded.

Synopsis

- zipStream :: (MonadThrow m, PrimMonad m) => ZipOptions -> ConduitM (ZipEntry, ZipData m) ByteString m Word64
- data ZipOptions = ZipOptions {
  - zipOpt64 :: !Bool
  - zipOptCompressLevel :: !Int
  - zipOptInfo :: !ZipInfo
  }
- data ZipInfo = ZipInfo {
  - zipComment :: ByteString
  }
- defaultZipOptions :: ZipOptions
- data ZipEntry = ZipEntry {
  - zipEntryName :: Either Text ByteString
  - zipEntryTime :: LocalTime
  - zipEntrySize :: Maybe Word64
  - zipEntryExternalAttributes :: Maybe Word32
  }
- data ZipData m
  - = ZipDataByteString ByteString
  - | ZipDataSource (ConduitM () ByteString m ())
- zipFileData :: MonadResource m => FilePath -> ZipData m

# Documentation

zipStream :: (MonadThrow m, PrimMonad m) => ZipOptions -> ConduitM (ZipEntry, ZipData m) ByteString m Word64 Source #

Stream produce a zip file, reading a sequence of entries with data. Although file data is never kept in memory (beyond a single `ZipDataByteString`), the format of zip files requires producing a final directory of entries at the end of the file, consuming an additional ~100 bytes of state per entry during streaming. The final result is the total size of the zip file.

Depending on options, the resulting zip file should be compatible with most unzipping applications. Any errors are thrown in the underlying monad (as `ZipError`s).

data ZipOptions Source #

Options controlling zip file parameters and features

Constructors

ZipOptions |

Fields

- zipOpt64 :: !Bool

  Allow `ZipDataSource`s over 4GB (reduces compatibility in some cases); this is automatically enabled for any files of known size (e.g., `zipEntrySize`)

- zipOptCompressLevel :: !Int

  Compress zipped files (0 = store only, 1 = minimal, 9 = best; non-zero improves compatibility, since some unzip programs don't supported stored, streamed files, including the one in this package)

- zipOptInfo :: !ZipInfo

  Other parameters to store in the zip file

data ZipInfo Source #

Summary information at the end of a zip stream.

Constructors

ZipInfo |

Fields

- zipComment :: ByteString

#### Instances

Instances details

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

defaultZipOptions :: ZipOptions Source #

data ZipEntry Source #

(The beginning of) a single entry in a zip stream, which may be any file or directory. As per zip file conventions, directory names should end with a slash and have no data, but this library does not ensure that.

Constructors

ZipEntry |

Fields

- zipEntryName :: Either Text ByteString

  File name (in posix format, no leading slashes), either UTF-8 encoded text or raw bytes (CP437), with a trailing slash for directories

- zipEntryTime :: LocalTime

  Modification time

- zipEntrySize :: Maybe Word64

  Size of file data (if known); checked on zipping and also used as hint to enable zip64. Disables compression for known 0-byte files.

- zipEntryExternalAttributes :: Maybe Word32

  Host-dependent attributes, often MS-DOS directory attribute byte (only supported when zipping)

#### Instances

Instances details

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

data ZipData m Source #

The data contents for a `ZipEntry`. For empty entries (e.g., directories), use `mempty`.

Constructors

ZipDataByteString ByteString | A known ByteString, which will be fully evaluated (not streamed)
ZipDataSource (ConduitM () ByteString m ()) | A byte stream producer, streamed (and compressed) directly into the zip

#### Instances

Instances details

Monad m => Monoid (ZipData m) Source # |
Instance details Defined in Codec.Archive.Zip.Conduit.Types Methods mempty :: ZipData m Source # mappend :: ZipData m -> ZipData m -> ZipData m Source # mconcat :: [ZipData m] -> ZipData m Source #
Monad m => Semigroup (ZipData m) Source # |
Instance details Defined in Codec.Archive.Zip.Conduit.Types Methods (<>) :: ZipData m -> ZipData m -> ZipData m Source # sconcat :: NonEmpty (ZipData m) -> ZipData m Source # stimes :: Integral b => b -> ZipData m -> ZipData m Source #

zipFileData :: MonadResource m => FilePath -> ZipData m Source #

Use a file on disk as `ZipData` (``ZipDataSource` . `sourceFile``).