print contents down one level
This commit is contained in:
parent
9ce8e0acf8
commit
2ab60618ff
49
tar-read.go
49
tar-read.go
@ -2,10 +2,12 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"archive/tar"
|
"archive/tar"
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -47,6 +49,10 @@ func main() {
|
|||||||
continue
|
continue
|
||||||
case tar.TypeReg:
|
case tar.TypeReg:
|
||||||
fmt.Println("File: ", name)
|
fmt.Println("File: ", name)
|
||||||
|
if strings.HasSuffix(name, "layer.tar") {
|
||||||
|
fmt.Println("Containing:")
|
||||||
|
printFilesInTar(tarReader, header)
|
||||||
|
}
|
||||||
// show the contents
|
// show the contents
|
||||||
// io.Copy(os.Stdout, tarReader)
|
// io.Copy(os.Stdout, tarReader)
|
||||||
default:
|
default:
|
||||||
@ -61,6 +67,49 @@ func main() {
|
|||||||
fmt.Printf("%+v\n", m)
|
fmt.Printf("%+v\n", m)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func printFilesInTar(parentReader *tar.Reader, h *tar.Header) {
|
||||||
|
size := h.Size
|
||||||
|
tarredBytes := make([]byte, size)
|
||||||
|
_, err := parentReader.Read(tarredBytes)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
r := bytes.NewReader(tarredBytes)
|
||||||
|
tarReader := tar.NewReader(r)
|
||||||
|
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)
|
||||||
|
case tar.TypeSymlink:
|
||||||
|
fmt.Println(" SymLink", name)
|
||||||
|
default:
|
||||||
|
fmt.Printf("%s : %c %s %s\n",
|
||||||
|
"hmmm?",
|
||||||
|
header.Typeflag,
|
||||||
|
"in file",
|
||||||
|
name,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type Manifest struct {
|
type Manifest struct {
|
||||||
Config string
|
Config string
|
||||||
RepoTags []string
|
RepoTags []string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user