Categorygithub.com/enr/zipext
modulepackage
0.4.0
Repository: https://github.com/enr/zipext.git
Documentation: pkg.go.dev

# 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

# Functions

Create build a zip containing inputPath.
Create build a zip containing inputPath but excluding files matching `exclusions` regex.
CreateFlat build a zip containing inputPath.
Extract contents of archivePath into the extractPath.
IsValidZip checks if the file is detected as zip: Java jar, war and ear files are zip.
Walk walks the zip file rooted at root, calling walkFn for each file or directory in the zip, including root.

# Type aliases

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