ocean.io.compress.ZipStream

Zlib decoder which supports pkzip and gzip archives, and can be stored in a pool.

In general it is not possible to stream pkzip archives. This is because the format supports some quirky features which were important in the days of floppy diskettes.

This class supports an important case where streaming is possible: an archive which consists of a single file stored at the start of the archive, using DEFLATE compression.

Needs linking with -lz.

Usage example:

        import ocean.io.compress.ZipStream;

        auto unzipper = new ZipStreamDecompressor;

        unzipper.reset();

        try
        {
            unzipper.start();
        }
        catch (Exception e)
        {
            // Error!
        }

        // `downloader` is a hypothetical source which provides chunks of
        // compressed data, eg downloaded from a socket
        // Before processing, it may be wise to check that the first bytes in
        // the file are equal to GZipFileSignature (for gzip files) or
        // ocean.util.compress.c.Zip.ZipLocalFileHeaderSignature (for pkzip); an
        // exception will be thrown if this is not true.

        foreach (compressed_chunk; downloader)
        {
            try
            {
                uncompressed = unzipper.decompress(compressed_chunk);
^
                Stdout.format("{}", uncompressed);
            }
            catch (Exception e)
            {
                // Error!
            }
        }

        if (!unzipper.end())
        {
            // Error!
        }

Members

Classes

ZipStreamDecompressor
class ZipStreamDecompressor

Zlib decoder which supports both gzip and pkzip compressed streams.

Static variables

GZipFileSignature
istring GZipFileSignature;

The file signature (magic number) used to identify a GZIP file

Meta