zip

package
v0.0.0-...-e2d100b Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2017 License: MIT Imports: 6 Imported by: 30

Documentation

Overview

Package zip provides a helper for the archive/zip package (archive/unarchive to/from a file/reader/writer)

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Archive

func Archive(inFilePath string, writer io.Writer, progress ProgressFunc) error

Archive compresses a file/directory to a writer

If the path ends with a separator, then the contents of the folder at that path are at the root level of the archive, otherwise, the root of the archive contains the folder as its only item (with contents inside).

If progress is not nil, it is called for each file added to the archive.

func ArchiveFile

func ArchiveFile(inFilePath string, outFilePath string, progress ProgressFunc) error

ArchiveFile compresses a file/directory to a file

See Archive() doc

Example
tmpDir, err := ioutil.TempDir("", "test_zip")
if err != nil {
	panic(err)
}
defer func() {
	_ = os.RemoveAll(tmpDir)
}()

outFilePath := filepath.Join(tmpDir, "foo.zip")

progress := func(archivePath string) {
	fmt.Println(archivePath)
}

err = ArchiveFile("testdata/foo", outFilePath, progress)
if err != nil {
	panic(err)
}
Output:

foo/bar
foo/baz/aaa

func Unarchive

func Unarchive(reader io.ReaderAt, readerSize int64, outFilePath string, progress ProgressFunc) error

Unarchive decompresses a reader to a directory

The data's size is required because the zip reader needs it.

The archive's content will be extracted directly to outFilePath.

If progress is not nil, it is called for each file extracted from the archive.

func UnarchiveFile

func UnarchiveFile(inFilePath string, outFilePath string, progress ProgressFunc) error

UnarchiveFile decompresses a file to a directory

See Unarchive() doc

Example
tmpDir, err := ioutil.TempDir("", "test_zip")
if err != nil {
	panic(err)
}
defer func() {
	_ = os.RemoveAll(tmpDir)
}()

progress := func(archivePath string) {
	fmt.Println(archivePath)
}

err = UnarchiveFile("testdata/foo.zip", tmpDir, progress)
if err != nil {
	panic(err)
}
Output:

foo/bar
foo/baz/aaa

Types

type ProgressFunc

type ProgressFunc func(archivePath string)

ProgressFunc is the type of the function called for each archive file.

Jump to

Keyboard shortcuts

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