zipread

package
v0.0.0-...-2ac2d53 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2022 License: BSD-3-Clause Imports: 22 Imported by: 0

Documentation

Overview

Package zip provides support for reading and writing ZIP archives.

See: https://www.pkware.com/appnote

This package does not support disk spanning.

A note about ZIP64:

To be backwards compatible the FileHeader has both 32 and 64 bit Size fields. The 64 bit fields will always contain the correct value and for normal archives both fields will be the same. For files requiring the ZIP64 format the 32 bit fields will be 0xffffffff and the 64 bit fields must be used instead.

Index

Constants

View Source
const (
	Store   = zip.Store
	Deflate = zip.Deflate
)

Variables

View Source
var (
	ErrFormat    = zip.ErrFormat
	ErrAlgorithm = zip.ErrAlgorithm
	ErrChecksum  = zip.ErrChecksum
)
View Source
var NewWriter = zip.NewWriter

Functions

func GzipWrapper

func GzipWrapper(r io.Reader, digest, decompressedSize uint32) io.Reader

GzipWrapper wraps a reader with gzip headers and footers.

func RegisterDecompressor

func RegisterDecompressor(method uint16, dcomp Decompressor)

RegisterDecompressor allows custom decompressors for a specified method ID. The common methods Store and Deflate are built in.

Types

type Decompressor

type Decompressor func(r io.Reader) io.ReadCloser

A Decompressor returns a new decompressing reader, reading from r. The ReadCloser's Close method must be used to release associated resources. The Decompressor itself must be safe to invoke from multiple goroutines simultaneously, but each returned reader will be used only by one goroutine at a time.

type File

type File struct {
	FileHeader
	// contains filtered or unexported fields
}

A File is a single file in a ZIP archive. The file information is in the embedded FileHeader. The file content can be accessed by calling Open.

func (*File) Open

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

Open returns a ReadCloser that provides access to the File's contents. Multiple files may be read concurrently.

func (*File) OpenAsGzip

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

OpenAsGzip returns a ReadCloser that provides access to the File's compressed contents. This method returns an ErrAlgorithm error if the zip is not compressed using deflate.

type FileHeader

type FileHeader = zip.FileHeader

func FileInfoHeader

func FileInfoHeader(fi fs.FileInfo) (*FileHeader, error)

FileInfoHeader creates a partially-populated FileHeader from an fs.FileInfo. Because fs.FileInfo's Name method returns only the base name of the file it describes, it may be necessary to modify the Name field of the returned header to provide the full path name of the file. If compression is desired, callers should set the FileHeader.Method field; it is unset by default.

type FileSource

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

func SourceFromFile

func SourceFromFile(name string) *FileSource

func (*FileSource) Range

func (fs *FileSource) Range(ctx context.Context, offset, length int64) (data io.ReadCloser, err error)

func (*FileSource) RangeFromEnd

func (fs *FileSource) RangeFromEnd(ctx context.Context, length int64) (data io.ReadCloser, sourceLength int64, err error)

type Reader

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

A Reader serves content from a ZIP archive.

func Open

func Open(source Source) (*Reader, error)

func (*Reader) Open

func (r *Reader) Open(name string) (fs.File, error)

Open opens the named file in the ZIP archive, using the semantics of fs.FS.Open: paths are always slash separated, with no leading / or ../ elements.

func (*Reader) OpenLookup

func (r *Reader) OpenLookup(name string) (*File, error)

func (*Reader) RegisterDecompressor

func (z *Reader) RegisterDecompressor(method uint16, dcomp Decompressor)

RegisterDecompressor registers or overrides a custom decompressor for a specific method ID. If a decompressor for a given method is not found, Reader will default to looking up the decompressor at the package level.

type ReaderAtSource

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

func SourceFromReaderAt

func SourceFromReaderAt(r io.ReaderAt, size int64) *ReaderAtSource

func (*ReaderAtSource) Range

func (ras *ReaderAtSource) Range(ctx context.Context, offset, length int64) (data io.ReadCloser, err error)

func (*ReaderAtSource) RangeFromEnd

func (ras *ReaderAtSource) RangeFromEnd(ctx context.Context, length int64) (data io.ReadCloser, sourceLength int64, err error)

type Source

type Source interface {
	Range(ctx context.Context, offset, length int64) (data io.ReadCloser, err error)
	RangeFromEnd(ctx context.Context, length int64) (data io.ReadCloser, sourceLength int64, err error)
}

func PrefetchTail

func PrefetchTail(ctx context.Context, s Source, amount int64) (Source, error)

type Writer

type Writer = zip.Writer

Jump to

Keyboard shortcuts

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