-
Notifications
You must be signed in to change notification settings - Fork 5
/
maketar.go
48 lines (40 loc) 路 952 Bytes
/
maketar.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
package checker
import (
"bytes"
"testing"
"github.com/itchio/arkive/tar"
"github.com/itchio/savior"
)
func MakeTar(t *testing.T, sink *Sink) []byte {
buf := new(bytes.Buffer)
tw := tar.NewWriter(buf)
for _, item := range sink.Items {
switch item.Entry.Kind {
case savior.EntryKindDir:
must(t, tw.WriteHeader(&tar.Header{
Name: item.Entry.CanonicalPath,
Typeflag: tar.TypeDir,
Mode: 0755,
}))
case savior.EntryKindFile:
must(t, tw.WriteHeader(&tar.Header{
Name: item.Entry.CanonicalPath,
Typeflag: tar.TypeReg,
Size: int64(len(item.Data)),
Mode: 0644,
}))
_, err := tw.Write(item.Data)
must(t, err)
case savior.EntryKindSymlink:
must(t, tw.WriteHeader(&tar.Header{
Name: item.Entry.CanonicalPath,
Typeflag: tar.TypeSymlink,
Mode: 0644,
Linkname: item.Entry.Linkname,
}))
}
}
err := tw.Close()
must(t, err)
return buf.Bytes()
}