Skip to content

Commit

Permalink
Print layers
Browse files Browse the repository at this point in the history
  • Loading branch information
willmurphyscode committed May 20, 2018
1 parent ee9cec9 commit 9ce8e0a
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion tar-read.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"archive/tar"
"encoding/json"
"fmt"
"io"
"os"
Expand All @@ -22,7 +23,8 @@ func main() {
// }

tarReader := tar.NewReader(f)

targetName := "manifest.json"
var m Manifest
for {
header, err := tarReader.Next()

Expand All @@ -36,6 +38,9 @@ func main() {
}

name := header.Name
if name == targetName {
m = handleManifest(tarReader, header)
}

switch header.Typeflag {
case tar.TypeDir:
Expand All @@ -53,4 +58,26 @@ func main() {
)
}
}
fmt.Printf("%+v\n", m)
}

type Manifest struct {
Config string
RepoTags []string
Layers []string
}

func handleManifest(r *tar.Reader, header *tar.Header) Manifest {
size := header.Size
manifestBytes := make([]byte, size)
_, err := r.Read(manifestBytes)
if err != nil {
panic(err)
}
var m [1]Manifest
err = json.Unmarshal(manifestBytes, &m)
if err != nil {
panic(err)
}
return m[0]
}

0 comments on commit 9ce8e0a

Please sign in to comment.