This commit is contained in:
2026-06-15 01:20:30 +03:00
parent b32279deaf
commit 80309aab99
20 changed files with 149 additions and 40 deletions

View File

@@ -1,8 +1,14 @@
package util
import (
"bytes"
"fmt"
"hash/crc32"
"io"
"os"
"testing"
"gordenko.dev/dima/textutil"
)
var page = make([]byte, 4096)
@@ -19,3 +25,38 @@ func BenchmarkCRC32IEEE(b *testing.B) {
crc32.Checksum(page, ieeeTable)
}
}
func TestHash(t *testing.T) {
raw, err := os.ReadFile("../b")
if err != nil {
t.Fatal(err)
}
buf, err := textutil.ParseHex(string(raw))
if err != nil {
t.Fatal(err)
}
fmt.Println(CalculateCRC32(buf))
w := bytes.NewBuffer(nil)
w.Write([]byte{
0, 0, 0, 0, 0, 0, 0, 0, 0, // size (max 9 byte)
})
hasher := NewHasher()
multi := io.MultiWriter(w, hasher)
i := 0
for i < len(buf) {
end := i + 50
if end >= len(buf) {
end = len(buf)
}
multi.Write(buf[i:end])
i += 50
}
fmt.Println(hasher.Sum32())
}