resources: Add FromOpts for more effective resource creation

E.g. when the targetPath already contains a hash or if the resource content is expensive to create.
This commit is contained in:
Bjørn Erik Pedersen
2025-01-03 18:36:44 +01:00
parent d913f46a8b
commit 723e3f4342
2 changed files with 81 additions and 7 deletions

View File

@@ -38,6 +38,19 @@ func XXHashFromReader(r io.Reader) (uint64, int64, error) {
return h.Sum64(), size, nil
}
// XxHashFromReaderHexEncoded calculates the xxHash for the given reader
// and returns the hash as a hex encoded string.
func XxHashFromReaderHexEncoded(r io.Reader) (string, error) {
h := getXxHashReadFrom()
defer putXxHashReadFrom(h)
_, err := io.Copy(h, r)
if err != nil {
return "", err
}
hash := h.Sum(nil)
return hex.EncodeToString(hash), nil
}
// XXHashFromString calculates the xxHash for the given string.
func XXHashFromString(s string) (uint64, error) {
h := xxhash.New()