Files
gocqlx/migrate/checksum.go

35 lines
584 B
Go
Raw Normal View History

2017-09-22 13:47:15 +02:00
// 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"
"io/fs"
2017-09-22 13:47:15 +02:00
)
var encode = hex.EncodeToString
func checksum(b []byte) string {
v := md5.Sum(b)
return encode(v[:])
}
func fileChecksum(f fs.FS, path string) (string, error) {
file, err := f.Open(path)
2017-09-22 13:47:15 +02:00
if err != nil {
return "", nil
}
defer file.Close()
2017-09-22 13:47:15 +02:00
h := md5.New()
if _, err := io.Copy(h, file); err != nil {
2017-09-22 13:47:15 +02:00
return "", err
}
v := h.Sum(nil)
return encode(v), nil
2017-09-22 13:47:15 +02:00
}