Add HasPrefix utility function
package util
import (
+ "bytes"
"fmt"
"os"
"syscall"
@@ -29,6 +30,15 @@ func UnprefixKey(key, prefix []byte) ([]byte, error) {
return key[len(prefix)+1:], nil
}
+// HasPrefix checks if the given key was prefixed with the given prefix using the PrefixKey function.
+func HasPrefix(key, prefix []byte) bool {
+ if len(prefix) == 0 {
+ return false
+ }
+ p := append(prefix, byte(0))
+ return bytes.HasPrefix(key, p)
+}
+
func FileExists(filePath string) bool {
_, err := os.Stat(filePath)
return !os.IsNotExist(err)
