Files
lpm/checksum/checksum.go
zeekay 7d7127a687 deps: update to latest luxfi packages
- Update node v1.16.15 → v1.19.8
- Update crypto v1.17.0 → v1.17.4
- Update database v1.2.0 → v1.2.1
- Update geth v1.16.34 → v1.16.35
- Update ids v1.1.0 → v1.1.1
- Update Go 1.25 → 1.25.1
- Update copyright year to 2025
2025-09-30 00:05:18 +00:00

47 lines
669 B
Go

// Copyright (C) 2019-2025, Lux Partners Limited. All rights reserved.
// See the file LICENSE for licensing terms.
package checksum
import (
"crypto/sha256"
"hash"
"io"
"github.com/spf13/afero"
)
type Checksummer interface {
Checksum(path string) []byte
}
var _ Checksummer = &SHA256{}
func NewSHA256(fs afero.Fs) *SHA256 {
return &SHA256{
h: sha256.New(),
Fs: fs,
}
}
type SHA256 struct {
h hash.Hash
Fs afero.Fs
}
func (s SHA256) Checksum(path string) []byte {
defer s.h.Reset()
f, err := s.Fs.Open(path)
if err != nil {
return nil
}
defer f.Close()
if _, err := io.Copy(s.h, f); err != nil {
return nil
}
return s.h.Sum(nil)
}