gounzip

package module
v0.0.0-...-e6741fe Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2018 License: GPL-3.0 Imports: 5 Imported by: 0

README

gounzip

A cross-platform utility for recursive unzipping in Go, with zero dependencies.

Install

go get github.com/duncanhall/gounzip

Usage

By default, only the source of the zip file is required:

gounzip.Unzip("/home/project/archive.zip")

This will unzip to a folder next to the zip file, giving it the same name as the zip (with extension removed). If the default output directory does not exist, it is crated.

Eg, the the example above creates a new driectory at /home/project/archive and extracts the contents of the zip into it.

To specifiy a destination directory, provide a gounzip.Destination setter:

gounzip.Unzip("/home/project/archive.zip", gounzip.Destination("/home/output/project"))

You can skip parts of the zip hierarchy by providing a gounzip.StripComponents setter (similar to tar --strip-components).

For example supplying gounzip.StripComponents(1) will ignore the top-most folder from the output.`

gounzip.Unzip("/home/project/archive.zip", gounzip.StripComponents(1))

This can be useful when a top-level folder was zipped, rather than just it's content and you don't want the folder to appear in the output.

Options can be combined, in any order:

gounzip.Unzip("/project/templates.zip", gounzip.StripComponents(1), gounzip.Destination("/project-templates"))

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Unzip

func Unzip(src string, options ...Option) error

Unzip accepts a path to a compressed .zip file and outputs the contents Optional arguments are passed in as Option setters

Types

type Option

type Option func(*Options)

Option is a setter for assigning values to Options

func DeleteSource

func DeleteSource(d bool) Option

DeleteSource creates a setter for Options.DeleteSource values

func Destination

func Destination(dest string) Option

Destination creates a setter for Options.Destination values

func StripComponents

func StripComponents(n uint) Option

StripComponents creates a setter for Options.StripComponents values

type Options

type Options struct {
	// Destination directory of the unzipped contents.
	// If the directory does not exist it will be created.
	// Defaults to match path and name of the source zip, without the file extension
	Destination string

	// Number of leading components to strip from file paths (same as tar --strip-components)
	// Defaults to 0
	StripComponents uint

	// Whether the original zip should be removed after unzipping
	// Defaults to false
	DeleteSource bool
}

Options passed to the Unzip method

Jump to

Keyboard shortcuts

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