-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvisit.go
64 lines (51 loc) · 1.07 KB
/
visit.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
51
52
53
54
55
56
57
58
59
60
61
62
63
package kelvin
import (
"fmt"
"os"
"io/ioutil"
"archive/zip"
)
type ZipFile struct {
name string
body []byte
}
var ( zip_files = []ZipFile{} )
func Visit(path string, f os.FileInfo, err error) error {
if f.IsDir() {
return nil
}
body, err := ioutil.ReadFile(path)
if err != nil {
return err
}
zf := ZipFile{
name: path,
body: body,
}
zip_files = append(zip_files, zf)
return nil
}
// FIXME: Should write the file during visit instead of stuffing it all into memory
func WriteZipFile(archive *os.File) (string, error) {
w := zip.NewWriter(archive)
for _, file := range zip_files {
f, err := w.Create(file.name)
if err != nil {
return "", err
}
_, err = f.Write(file.body)
if err != nil {
return "", err
}
}
// Make sure to check the error on Close.
err := w.Close()
if err != nil {
return "", err
}
return archive.Name(), nil
}
func DumpZipFiles() error {
fmt.Printf("%v", zip_files)
return nil
}