zipext

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2022 License: Apache-2.0 Imports: 9 Imported by: 4

README

Go zipext

CI Linux CI Windows PkgGoDev Go Report Card

Go library to manipulate zip files.

Import library:

    import (
        "github.com/enr/zipext"
    )

Create a zip archive:

    contents := "/path/to/files"
    zipPath := "/path/to/archive.zip"
    err := zipext.Create(contents, zipPath)
    if err != nil {
        t.Errorf("error in Create(%s,%s): %s %s", contents, zipPath, reflect.TypeOf(err), err.Error())
    }

Extract contents from zip:

    err = zipext.Extract(zipPath, extractPath)
    if err != nil {
        t.Errorf("error in Extract(%s,%s): %s %s", zipPath, unzipDir, reflect.TypeOf(err), err.Error())
    }

Visit zip contents:

    err := zipext.Walk(path, func(f *zip.File, err error) error {
        if err != nil {
            return err
        }
        fmt.Printf("- %#v\n", f)
        return nil
    })

Check if file is valid zip:

    p := "/path/to/archive.zip"
    valid, err := zipext.IsValidZip(p)
    if err != nil {
        t.Errorf("got error checking for valid zip '%s'", p)
    }

License

Apache 2.0 - see LICENSE file.

Copyright 2014-TODAY zipext contributors

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create(inputPath string, zipPath string) error

Create build a zip containing inputPath. If inputPath is a directory the zip will contain the directory

func CreateExcluding added in v0.4.0

func CreateExcluding(inputPath string, zipPath string, exclusions []string) error

Create build a zip containing inputPath but excluding files matching `exclusions` regex. If inputPath is a directory the zip will contain the directory

func CreateFlat

func CreateFlat(inputPath string, zipPath string) error

CreateFlat build a zip containing inputPath. If inputPath is a directory the zip will contain the directory contents

func Extract

func Extract(archivePath string, extractPath string) error

Extract contents of archivePath into the extractPath

func IsValidZip

func IsValidZip(maybeZip string) (bool, error)

IsValidZip checks if the file is detected as zip: Java jar, war and ear files are zip

func Walk

func Walk(path string, walkFn WalkFunc) error

Walk walks the zip file rooted at root, calling walkFn for each file or directory in the zip, including root. All errors that arise visiting files and directories are filtered by walkFn.

Types

type WalkFunc

type WalkFunc func(file *zip.File, err error) error

WalkFunc is the type of the function called for each file or directory visited by Walk.

If there was a problem walking to the file or directory named by path, the incoming error will describe the problem and the function can decide how to handle that error (and Walk will not descend into that directory). If an error is returned, processing stops.

TODO: this signature requires client code import archive/zip

Jump to

Keyboard shortcuts

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