This commit is contained in:
Michał Matczuk
2017-09-22 13:47:15 +02:00
parent fd5efe40eb
commit 3351b1f9a3
6 changed files with 247 additions and 2 deletions

34
migrate/checksum.go Normal file
View File

@@ -0,0 +1,34 @@
// Copyright (C) 2017 ScyllaDB
// Use of this source code is governed by a ALv2-style
// license that can be found in the LICENSE file.
package migrate
import (
"crypto/md5"
"encoding/hex"
"io"
"os"
)
var encode = hex.EncodeToString
func checksum(b []byte) string {
v := md5.Sum(b)
return encode(v[:])
}
func fileChecksum(path string) (string, error) {
f, err := os.Open(path)
if err != nil {
return "", nil
}
defer f.Close()
h := md5.New()
if _, err := io.Copy(h, f); err != nil {
return "", err
}
v := h.Sum(nil)
return encode(v[:]), nil
}