Initial commit
This commit is contained in:
commit
55a1efa08f
60 changed files with 5485 additions and 0 deletions
3
lang/go/utils/dirhash/go.mod
Normal file
3
lang/go/utils/dirhash/go.mod
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
module puck.moe/zilch/go/dirhash
|
||||
|
||||
go 1.22.5
|
||||
52
lang/go/utils/dirhash/main.go
Normal file
52
lang/go/utils/dirhash/main.go
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
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()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue