Created
May 8, 2014 13:13
-
-
Save alexlarsson/844e769979a83485ebcd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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