zipstream

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2019 License: BSD-3-Clause Imports: 13 Imported by: 0

README

ZipStream

Enables zip file streaming from an io.Reader. Now with ZIP64 support.

Example

package main

import (
	"github.com/dbregman/zipstream"
	"bytes"
	"io"
	"log"
	"io/ioutil"
	)

func main() {
	// Read the first compressed file from a zip file.
	var zipFile bytes.Buffer
	zr := zipstream.NewReader(&zipFile)
	meta, err := zr.Next()
	if err != nil {
		if err != io.EOF {
			panic(err)
		}
	}
	log.Printf("file name: %s", meta.Name)
	compressedFile, err := ioutil.ReadAll(zr)
	if err != nil {
		panic(err)
	}
	log.Printf("file content: %s", string(compressedFile[:]))
}

History

https://github.com/golang/go/issues/10568

Documentation

Overview

Package zipstream provides support for reading ZIP archives through an io.Reader.

Index

Constants

View Source
const (
	Store   uint16 = 0 // no compression
	Deflate uint16 = 8 // DEFLATE compressed
)

Compression methods.

Variables

This section is empty.

Functions

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 Reader

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

A Reader provides sequential access to the contents of a zip archive. A zip archive consists of a sequence of files, The Next method advances to the next file in the archive (including the first), and then it can be treated as an io.Reader to access the file's data. The Buffered method recovers any bytes read beyond the end of the zip file, necessary if you plan to process anything after it that is not another zip file.

func NewReader

func NewReader(r io.Reader) *Reader

NewReader creates a new Reader reading from r.

func (*Reader) Buffered

func (r *Reader) Buffered() io.Reader

Buffered returns any bytes beyond the end of the zip file that it may have read. These are necessary if you plan to process anything after it, that isn't another zip file.

func (*Reader) Next

func (r *Reader) Next() (*zip.FileHeader, error)

Next advances to the next entry in the zip archive.

io.EOF is returned when the end of the zip file has been reached. If Next is called again, it will presume another zip file immediately follows and it will advance into it.

func (*Reader) RegisterDecompressor

func (r *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.

Jump to

Keyboard shortcuts

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