-
Notifications
You must be signed in to change notification settings - Fork 2
/
pack.go
50 lines (42 loc) · 1.05 KB
/
pack.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"fmt"
"os"
"path/filepath"
"github.com/dustin/go-humanize"
"github.com/rubiojr/rapi/crypto"
"github.com/rubiojr/rapi/examples/util"
"github.com/rubiojr/rapi/pack"
)
func main() {
k := util.FindAndOpenKey()
dataDir := filepath.Join(util.RepoPath, "data")
packWalker := func(path string, info os.FileInfo, err error) error {
if info.IsDir() {
return nil
}
listPackBlobs(path, info, k)
return nil
}
err := filepath.Walk(dataDir, packWalker)
util.CheckErr(err)
}
// List pack blobs and some of their attributes
func listPackBlobs(path string, info os.FileInfo, k *crypto.Key) {
handle, err := os.Open(path)
util.CheckErr(err)
blobs, err := pack.List(k, handle, info.Size())
util.CheckErr(err)
fmt.Println("Pack file: ", path)
fmt.Println(" Size: ", humanize.Bytes(uint64(info.Size())))
fmt.Println(" Blobs: ", len(blobs))
for _, blob := range blobs {
// Describe blob and print content
fmt.Printf(
" %s: %s (%s)\n",
blob.Type.String(),
blob.ID.String(),
humanize.Bytes(uint64(blob.Length)),
)
}
}