aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/pkg/pkg.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/pkg/pkg.go')
-rw-r--r--internal/pkg/pkg.go20
1 files changed, 15 insertions, 5 deletions
diff --git a/internal/pkg/pkg.go b/internal/pkg/pkg.go
index 40bad6ff..64df5df4 100644
--- a/internal/pkg/pkg.go
+++ b/internal/pkg/pkg.go
@@ -24,6 +24,16 @@ type (
ID Checksum
)
+// Encode is abbreviation for base64.URLEncoding.EncodeToString(checksum[:]).
+func Encode(checksum Checksum) string {
+ return base64.URLEncoding.EncodeToString(checksum[:])
+}
+
+// encode is abbreviation for base64.URLEncoding.EncodeToString(checksum[:]).
+func encode(checksum *Checksum) string {
+ return base64.URLEncoding.EncodeToString(checksum[:])
+}
+
// MustDecode decodes a string representation of [Checksum] and panics if there
// is a decoding error or the resulting data is too short.
func MustDecode(s string) (checksum Checksum) {
@@ -143,7 +153,7 @@ func (c *Cache) LoadFile(id ID) (
) {
pathname = c.base.Append(
dirIdentifier,
- base64.URLEncoding.EncodeToString(id[:]),
+ Encode(id),
)
c.mu.RLock()
@@ -160,15 +170,15 @@ type ChecksumMismatchError struct {
}
func (e *ChecksumMismatchError) Error() string {
- return "got " + base64.URLEncoding.EncodeToString(e.Got[:]) +
- " instead of " + base64.URLEncoding.EncodeToString(e.Want[:])
+ return "got " + Encode(e.Got) +
+ " instead of " + Encode(e.Want)
}
// pathname returns the content-addressed pathname for a [Checksum].
func (c *Cache) pathname(checksum *Checksum) *check.Absolute {
return c.base.Append(
dirChecksum,
- base64.URLEncoding.EncodeToString(checksum[:]),
+ encode(checksum),
)
}
@@ -176,7 +186,7 @@ func (c *Cache) pathname(checksum *Checksum) *check.Absolute {
func (c *Cache) pathnameIdent(id *ID) *check.Absolute {
return c.base.Append(
dirIdentifier,
- base64.URLEncoding.EncodeToString(id[:]),
+ encode((*Checksum)(id)),
)
}