ziputil

package
v5.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: May 27, 2020 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Archive

func Archive(sourceFolder, destinationZip string) error

Archive creates a zip from the contents of the sourceFolder at the destinationZip location.

func Clean

func Clean(path ...string) string

Clean converts a path into a zip style path by replacing backslashes with forward-slashes and making the paths relative by removing leading "/" and "./".

func Extract

func Extract(z *zip.Reader, zipDirectory, osDirectory string) error

Extracts the contents of the zipDirectory to the given OS osDirectory. This routine is overly strict and doesn't allow extracting _any_ files that contain "..".

Example
tmp, err := ioutil.TempDir("", "ziptest")
if err != nil {
	panic(err)
}
defer os.RemoveAll(tmp)

zf := openZipfile()

// extract all files/dirs under the path/to directory to tmp
if err := Extract(zf, "path/to", tmp); err != nil {
	panic(err)
}

stream.Copy(stream.FromFile(tmp, "my", "file.txt"), stream.ToWriter(os.Stdout))
Output:

Hello, world!

func Find

func Find(z *zip.Reader, path ...string) *zip.File

Find returns a pointer to the file at the given path if it exists, otherwise nil.

Example
zf := openZipfile()
fmt.Println(Find(zf, "does", "not", "exist"))
fmt.Println(Find(zf, "path/to/my", "file.txt").Name)
Output:

<nil>
path/to/my/file.txt

func Join

func Join(path ...string) string

Joins a path for use in a zip file.

func List

func List(z *zip.Reader, w io.Writer)

List writes a ls -la style listing of the zipfile to the given writer.

Example
zf := openZipfile()
List(zf, os.Stdout)
Output:

MODE        SIZE  NAME
-rw-rw-rw-  13    path/to/my/file.txt

func Open

func Open(z *zip.Reader, path ...string) (io.ReadCloser, error)

Opens the file at the given path if possible, otherwise returns an error.

Example
zf := openZipfile()
source := stream.FromReadCloserError(Open(zf, "path/to/my/file.txt"))
stream.Copy(source, stream.ToWriter(os.Stdout))
Output:

Hello, world!

func Unarchive

func Unarchive(zipFile, destination string) error

Unarchive opens the specified file and extracts all of its contents to the destination.

Types

This section is empty.

Jump to

Keyboard shortcuts

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