pomerium/config/envoyconfig/filemgr/name.go
Caleb Doxsey dc9a6bdb81
replace xxhash with xxh3 (#5457)
* update config file paths hash

* update filemgr

* use xxh3 for hashutil.Hash

* update hashutil digest, fix trace buffer test

* update comments

* update namegen, go mod tidy
2025-01-31 08:44:08 -07:00

18 lines
512 B
Go

package filemgr
import (
"fmt"
"path/filepath"
"github.com/martinlindhe/base36"
"github.com/zeebo/xxh3"
)
// GetFileNameWithBytesHash constructs a filename using a base filename and a hash of
// the data. For example: GetFileNameWithBytesHash("example.txt", []byte{...}) ==> "example-abcd1234.txt"
func GetFileNameWithBytesHash(base string, data []byte) string {
h := xxh3.Hash(data)
he := base36.Encode(h)
ext := filepath.Ext(base)
return fmt.Sprintf("%s-%x%s", base[:len(base)-len(ext)], he, ext)
}