gozip

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

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

Go to latest
Published: Jul 21, 2022 License: MIT Imports: 7 Imported by: 0

README

Gozip

The gozip library can be used to add, list and extract zipped content into a zip file or behind an executable binary. The use case for adding zip files behind a binary is to distribute one executable that can automatically extract required files.

Originally forked from https://github.com/sanderhahn/gozip

go install -v -u github.com/ActiveState/gozip/cmd/gozip@latest

The api consist of the Zip, UnzipList and Unzip functions:

import "github.com/ActiveState/gozip"

// zip files/directories into file.zip (file.zip can also be an executable)
err := gozip.Zip("file.zip", []string{"content.txt", ...})

// list the zip file contents
list, err := gozip.UnzipList("file.zip")
for _, f := range list {
        fmt.Printf("%s\n", f)
}

// unzip the zip file into destination
err := gozip.Unzip("file.zip", "destination")

Self Extracting Binary

The zip functions also work when the actual zip content starts behind a binary. For example its possible to append the readme.md into the gozip command.

$ gozip
Usage of gozip:
  -c	create zip (arguments: zipfile [files...])
  -l	list zip (arguments: zipfile)
  -x	extract zip (arguments: zipfile [destination]

# make temporary copy of gozip
$ cp `which gozip` gozip

# add readme.md and LICENSE.txt as zip archive behind binary
$ gozip -c gozip readme.md LICENSE.txt

# list archive with the binary itself
$ ./gozip -l ./gozip
readme.md
LICENSE.txt

License

The source code uses the MIT license.

Contributors: @dixonwille

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsZip

func IsZip(path string) bool

IsZip checks to see if path is already a zip file

func Unzip

func Unzip(zippath string, destination string) (err error)

Unzip unzips the file zippath and puts it in destination

func UnzipList

func UnzipList(path string) (list []string, err error)

UnzipList Lists all the files in zip file

func Zip

func Zip(path string, dirs []string) (err error)

Zip takes all the files (dirs) and zips them into path

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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