53 lines
716 B
Go
53 lines
716 B
Go
|
|
package main
|
||
|
|
|
||
|
|
import (
|
||
|
|
"archive/zip"
|
||
|
|
"crypto/sha256"
|
||
|
|
"fmt"
|
||
|
|
"io"
|
||
|
|
"os"
|
||
|
|
"sort"
|
||
|
|
)
|
||
|
|
|
||
|
|
func main() {
|
||
|
|
out, err := os.OpenFile(os.Getenv("out"), os.O_CREATE|os.O_RDWR, 0666)
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
|
||
|
|
var files []string
|
||
|
|
|
||
|
|
f, err := zip.OpenReader(os.Getenv("src"))
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
|
||
|
|
for _, file := range f.File {
|
||
|
|
if file.Mode().IsDir() {
|
||
|
|
continue
|
||
|
|
}
|
||
|
|
|
||
|
|
files = append(files, file.Name)
|
||
|
|
}
|
||
|
|
|
||
|
|
sort.Strings(files)
|
||
|
|
for _, rel := range files {
|
||
|
|
f, err := f.Open(rel)
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
defer f.Close()
|
||
|
|
|
||
|
|
hash := sha256.New()
|
||
|
|
_, err = io.Copy(hash, f)
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
|
||
|
|
fmt.Fprintf(out, "%x %s\n", hash.Sum(nil), rel)
|
||
|
|
}
|
||
|
|
|
||
|
|
out.Close()
|
||
|
|
f.Close()
|
||
|
|
}
|