Skip to content

Instantly share code, notes, and snippets.

@alexlarsson
Created May 8, 2014 13:13
Show Gist options
  • Save alexlarsson/844e769979a83485ebcd to your computer and use it in GitHub Desktop.
Save alexlarsson/844e769979a83485ebcd to your computer and use it in GitHub Desktop.
package main
import (
"archive/tar"
"compress/gzip"
"fmt"
"io"
"os"
)
func ListTar(f io.Reader) error {
tr := tar.NewReader(f)
// Iterate through the files in the archive.
for {
hdr, err := tr.Next()
if err == io.EOF {
// end of tar archive
break
}
if err != nil {
return err
}
fmt.Printf("%s:\n", hdr.Name)
}
return nil
}
func main() {
if len(os.Args) < 2 {
fmt.Printf("To few args\n")
os.Exit(1)
}
f, err := os.Open(os.Args[1])
if err != nil {
panic(err)
}
r, err := gzip.NewReader(f)
if err != nil {
panic(err)
}
err = ListTar(r)
if err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment