]> Sergey Matveev's repositories - syncer.git/blobdiff - syncer.go
Refactoring
[syncer.git] / syncer.go
index e745d739b4f0114ba773925652841288351dbe38..f6159b3a387ceca3a869b30f6fb390576097fdc0 100644 (file)
--- a/syncer.go
+++ b/syncer.go
@@ -1,6 +1,6 @@
 /*
 syncer -- stateful file/device data syncer.
-Copyright (C) 2015-2020 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2015-2022 Sergey Matveev <stargrave@stargrave.org>
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -28,9 +28,11 @@ import (
        "os"
        "runtime"
 
-       "github.com/dchest/blake2b"
+       "lukechampine.com/blake3"
 )
 
+const HashSize = 256 / 8
+
 var (
        blkSize   = flag.Int64("blk", 2*1<<10, "Block size (KiB)")
        statePath = flag.String("state", "state.bin", "Path to statefile")
@@ -86,7 +88,7 @@ func main() {
        defer dst.Close()
 
        // Check if we already have statefile and read the state
-       state := make([]byte, blake2b.Size*blocks)
+       state := make([]byte, HashSize*blocks)
        var i int64
        var tmp []byte
        if _, err := os.Stat(*statePath); err == nil {
@@ -178,8 +180,8 @@ func main() {
                sync := make(chan SyncEvent)
                syncs <- sync
                go func(i int64) {
-                       sum := blake2b.Sum512(buf[:n])
-                       sumState := state[i*blake2b.Size : i*blake2b.Size+blake2b.Size]
+                       sum := blake3.Sum256(buf[:n])
+                       sumState := state[i*HashSize : i*HashSize+HashSize]
                        if bytes.Compare(sumState, sum[:]) != 0 {
                                sync <- SyncEvent{i, buf, buf[:n]}
                                prn.Changed()