go-examples/zip
AJ ONeal da2fc01c62 add simple zip example 2019-08-05 02:00:28 -06:00
..
README.md add simple zip example 2019-08-05 02:00:28 -06:00
main.go add simple zip example 2019-08-05 02:00:28 -06:00
zip.go add simple zip example 2019-08-05 02:00:28 -06:00

README.md

Go Zip Example

An example of how to zip a directory in Go.

  • Utilizes filepath.Walk to traverse a directory (or single file)
  • Handles each of
    • Files (deflated, compressed)
    • Directories (empty, not compressed)
    • Symlinks (not compressed)
    • Skips irregular files (pipes, sockets, devices, chars)
  • Names zip file after the name of the directory
  • Trims path prefix
git clone https://git.coolaj86.com/coolaj86/go-examples.git
pushd go-examples/zip
go run . path/to/whatever
wrote whatever.zip

Separates concerns into functions for readability:

  • func main()
  • func Zip(w io.Writer, src string, trim string) error
    • zipOne
      • zipDirectory
      • zipFile
      • zipSymlink