hashzip

package
v0.0.0-...-4990f62 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 21, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NoCompression       = flate.NoCompression
	BestSpeed           = flate.BestSpeed
	BestCompression     = flate.BestCompression
	DefaultCompression  = flate.DefaultCompression
	ConstantCompression = flate.ConstantCompression
	HuffmanOnly         = flate.HuffmanOnly
)

These constants are copied from the flate package, so that code that imports "compress/gzip" does not also have to import "compress/flate".

Variables

This section is empty.

Functions

This section is empty.

Types

type DeflateWriter

type DeflateWriter struct {
	// contains filtered or unexported fields
}

A DeflateWriter is an io.WriteCloser. Writes to a Writer are compressed and written to w.

func NewDeflateWriter

func NewDeflateWriter(w io.Writer) *DeflateWriter

NewDeflateWriter returns a new Writer. Writes to the returned writer are compressed and written to w.

It is the caller's responsibility to call Close on the WriteCloser when done. Writes may be buffered and not flushed until Close.

Callers that wish to set the fields in Writer.Header must do so before the first call to Write or Close. The Comment and Name header fields are UTF-8 strings in Go, but the underlying format requires NUL-terminated ISO 8859-1 (Latin-1). NUL or non-Latin-1 runes in those strings will lead to an error on Write.

func NewDeflateWriterLevel

func NewDeflateWriterLevel(w io.Writer, level int) (*DeflateWriter, error)

NewDeflateWriterLevel is like NewDeflateWriter but specifies the compression level instead of assuming DefaultCompression.

The compression level can be DefaultCompression, NoCompression, or any integer value between BestSpeed and BestCompression inclusive. The error returned will be nil if the level is valid.

func (*DeflateWriter) Close

func (z *DeflateWriter) Close() error

Close closes the Writer, flushing any unwritten data to the underlying io.Writer, but does not close the underlying io.Writer.

func (*DeflateWriter) Flush

func (z *DeflateWriter) Flush() error

Flush flushes any pending compressed data to the underlying writer.

It is useful mainly in compressed network protocols, to ensure that a remote reader has enough data to reconstruct a packet. Flush does not return until the data has been written. If the underlying writer returns an error, Flush returns that error.

In the terminology of the zlib library, Flush is equivalent to Z_SYNC_FLUSH.

func (*DeflateWriter) Reset

func (z *DeflateWriter) Reset(w io.Writer)

Reset discards the Writer z's state and makes it equivalent to the result of its original state from NewWriter or NewWriterLevel, but writing to w instead. This permits reusing a Writer rather than allocating a new one.

func (*DeflateWriter) SetConcurrency

func (z *DeflateWriter) SetConcurrency(blockSize, blocks int) error

SetConcurrency finetunes the concurrency level if needed.

With this you can control the approximate size of your blocks, as well as how many you want to be processing in parallel.

Default values for this is SetConcurrency(defaultBlockSize, runtime.GOMAXPROCS(0)), meaning blocks are split at 1 MB and up to the number of CPU threads can be processing at once before the writer blocks.

func (*DeflateWriter) UncompressedSize

func (z *DeflateWriter) UncompressedSize() int

UncompressedSize will return the number of bytes written. pgzip only, not a function in the official gzip package.

func (*DeflateWriter) Write

func (z *DeflateWriter) Write(p []byte) (int, error)

Write writes a compressed form of p to the underlying io.Writer. The compressed bytes are not necessarily flushed to output until the Writer is closed or Flush() is called.

The function will return quickly, if there are unused buffers. The sent slice (p) is copied, and the caller is free to re-use the buffer when the function returns.

Errors that occur during compression will be reported later, and a nil error does not signify that the compression succeeded (since it is most likely still running) That means that the call that returns an error may not be the call that caused it. Only Flush and Close functions are guaranteed to return any errors up to that point.

type File

type File struct {
	Name               string
	UncompressedSize64 uint64
	FileHeader         zip.FileHeader
	Hash               string
	// contains filtered or unexported fields
}

File holds information about one file in a zip archive

func (*File) Open

func (f *File) Open() (io.ReadCloser, error)

Open opens the file for reading

type Reader

type Reader struct {
	File []*File
	// contains filtered or unexported fields
}

Reader defines the zip reader

func NewReader

func NewReader(r io.ReaderAt, size int64) (*Reader, error)

NewReader returns a new Reader reading from r, which is assumed to have the given size in bytes.

func (*Reader) GetFile

func (r *Reader) GetFile(name string) *File

GetFile gets the file by name

func (*Reader) GetFileByHash

func (r *Reader) GetFileByHash(hash string) *File

GetFileByHash gets the file by the hash value

func (*Reader) GetHash

func (r *Reader) GetHash(name string) string

GetHash gets the hash for the file name

type Writer

type Writer struct {
	io.Writer
	// contains filtered or unexported fields
}

Writer holds the data for writing to a zip archive, ignoring duplicate file names

func NewWriter

func NewWriter(w io.Writer) *Writer

NewWriter returns a new writer

func NewWriterLevel

func NewWriterLevel(w io.Writer, level int) *Writer

NewWriterLevel returns a new writer using the specified level

func (*Writer) Close

func (w *Writer) Close() error

Close closes the zip writer

func (*Writer) Copy

func (w *Writer) Copy(name string, zf *File) error

Copy copies the compressed contents of the source file to this archive

func (*Writer) Create

func (w *Writer) Create(name string) (io.Writer, error)

Create creates a new entry and returns a writer

func (*Writer) CreateHeader

func (w *Writer) CreateHeader(fh *zip.FileHeader) (io.Writer, error)

CreateHeader creates a new header entry and returns a writer

func (*Writer) Exists

func (w *Writer) Exists(name string) bool

Exists returns true if the given file exists in the archive

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL