just reading a tar

This commit is contained in:
Alex Goodman 2018-05-20 08:34:13 -04:00
parent 2245ffa042
commit ee9cec9323
No known key found for this signature in database
GPG Key ID: 05328C611D8A520E
2 changed files with 58 additions and 0 deletions

2
.gitignore vendored
View File

@ -10,3 +10,5 @@
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
image

56
tar-read.go Normal file
View File

@ -0,0 +1,56 @@
package main
import (
"archive/tar"
"fmt"
"io"
"os"
)
func main() {
f, err := os.Open("image/cache.tar")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer f.Close()
// gzf, err := gzip.NewReader(f)
// if err != nil {
// fmt.Println(err)
// os.Exit(1)
// }
tarReader := tar.NewReader(f)
for {
header, err := tarReader.Next()
if err == io.EOF {
break
}
if err != nil {
fmt.Println(err)
os.Exit(1)
}
name := header.Name
switch header.Typeflag {
case tar.TypeDir:
continue
case tar.TypeReg:
fmt.Println("File: ", name)
// show the contents
// io.Copy(os.Stdout, tarReader)
default:
fmt.Printf("%s : %c %s %s\n",
"hmmm?",
header.Typeflag,
"in file",
name,
)
}
}
}