"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
hash: add CRC-32 support
Cenk Alti8159658e67b8
diff --git a/fs/hash/hash.go b/fs/hash/hash.goindex bac03d414..54e638a3e 100644--- a/fs/hash/hash.go+++ b/fs/hash/hash.go@@ -6,6 +6,7 @@ import ("encoding/hex""fmt""hash"+ "hash/crc32""io""strings"@@ -40,13 +41,16 @@ const (// Whirlpool indicates Whirlpool supportWhirlpool+ // CRC32 indicates CRC-32 support+ CRC32+// None indicates no hashes are supportedNone Type = 0)// Supported returns a set of all the supported hashes by// HashStream and MultiHasher.-var Supported = NewHashSet(MD5, SHA1, Dropbox, QuickXorHash, Whirlpool)+var Supported = NewHashSet(MD5, SHA1, Dropbox, QuickXorHash, Whirlpool, CRC32)// Width returns the width in characters for any HashTypevar Width = map[Type]int{@@ -55,6 +59,7 @@ var Width = map[Type]int{Dropbox: 64,QuickXorHash: 40,Whirlpool: 128,+ CRC32: 8,}// Stream will calculate hashes of all supported hash types.@@ -96,6 +101,8 @@ func (h Type) String() string {return "QuickXorHash"case Whirlpool:return "Whirlpool"+ case CRC32:+ return "CRC-32"default:err := fmt.Sprintf("internal error: unknown hash type: 0x%x", int(h))panic(err)@@ -117,6 +124,8 @@ func (h *Type) Set(s string) error {*h = QuickXorHashcase "Whirlpool":*h = Whirlpool+ case "CRC-32":+ *h = CRC32default:return errors.Errorf("Unknown hash type %q", s)}@@ -149,6 +158,8 @@ func fromTypes(set Set) (map[Type]hash.Hash, error) {hashers[t] = quickxorhash.New()case Whirlpool:hashers[t] = whirlpool.New()+ case CRC32:+ hashers[t] = crc32.NewIEEE()default:err := fmt.Sprintf("internal error: Unsupported hash type %v", t)panic(err)diff --git a/fs/hash/hash_test.go b/fs/hash/hash_test.goindex db1254b58..cefcaffd5 100644--- a/fs/hash/hash_test.go+++ b/fs/hash/hash_test.go@@ -74,6 +74,7 @@ var hashTestSet = []hashTest{hash.Dropbox: "214d2fcf3566e94c99ad2f59bd993daca46d8521a0c447adf4b324f53fddc0c7",hash.QuickXorHash: "0110c000085000031c0001095ec00218d0000700",hash.Whirlpool: "eddf52133d4566d763f716e853d6e4efbabd29e2c2e63f56747b1596172851d34c2df9944beb6640dbdbe3d9b4eb61180720a79e3d15baff31c91e43d63869a4",+ hash.CRC32: "a6041d7e",},},// Empty data set@@ -85,6 +86,7 @@ var hashTestSet = []hashTest{hash.Dropbox: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",hash.QuickXorHash: "0000000000000000000000000000000000000000",hash.Whirlpool: "19fa61d75522a4669b44e39c1d2e1726c530232130d407f89afee0964997f7a73e83be698b288febcf88e3e03c4f0757ea8964e59b63d93708b138cc42a66eb3",+ hash.CRC32: "00000000",},},}