Files
gocqlx/migrate/checksum.go
Michał Matczuk 1668ca5832 Updated golandci-lint to 1.21.0
Signed-off-by: Michał Matczuk <michal@scylladb.com>
2019-11-07 16:13:50 -08:00

35 lines
564 B
Go

// 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
}