Categorygithub.com/Velocidex/zip
modulepackage
0.0.0-20210101070220-e7ecefb7aad7
Repository: https://github.com/velocidex/zip.git
Documentation: pkg.go.dev

# README

A Concurrent Zip writer

This is a fork of the Go standard library's Zip implementation which provides a better writer for multiple concurrent writers.

The standard library implementation requires files to be written in series. This is not very efficient and leads to significant slow downs when we need to write many files since each file is compressed on a single core.

This implementation is designed to work with many writers - each writer compresses the file independently into a zip file and then copies the compressed file into the archive when the writer is closed. This allows each file to be compressed concurrently.

The main different from the standard library is that created file writer instances need to be explicitey closed to ensure they are added to the archive (dont forget to check the error status of Close() as it confirms if the file was added correctly):

out_fd, err := zip.Create(name)
if err != nil {
    ...
}
_, err = ioutils.Copy(out_fd, in_reader)
if err != nil {
    ...
}
err = out_fd.Close()
if err != nil {
    ...
}

Pool interface

To make using this even easier, there is a CompressorPool implementation which accepts readers.

Each reader will be compressed and copied to the zip file by a worker in the pool. A call to pool.Close() will wait until all workers exit and allow the zip to be safely closed.

    pool := NewCompressorPool(context.Background(), zip, 10)

    pool.Compress(&Request{
        Reader: reader,
        Name:   "My filename",
    })

    err = pool.Close()
    if err != nil {
       ...
    }
    err = zip.Close()
    if err != nil {
       ...
    }

# Functions

An io.Copy() that respects context cancellations.
No description provided by the author
FileInfoHeader creates a partially-populated FileHeader from an os.FileInfo.
No description provided by the author
NewReader returns a new Reader reading from r, which is assumed to have the given size in bytes.
NewWriter returns a new Writer writing a zip file to w.
OpenReader will open the Zip file specified by name and return a ReadCloser.
RegisterCompressor registers custom compressors for a specified method ID.
RegisterDecompressor allows custom decompressors for a specified method ID.

# Constants

DEFLATE compressed.
no compression.

# Variables

No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
FileHeader describes a file within a zip file.
No description provided by the author
No description provided by the author
No description provided by the author
Writer implements a zip file writer.

# Type aliases

A Compressor returns a new compressing writer, writing to w.
A Decompressor returns a new decompressing reader, reading from r.