Skip to content

enr/zipext

Repository files navigation

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