feat: add EncodeString function
This commit is contained in:
parent
8f3af2084c
commit
488f8737c0
10
cid/cid.go
10
cid/cid.go
|
@ -3,6 +3,7 @@ package cid
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"github.com/multiformats/go-multibase"
|
||||
)
|
||||
|
@ -31,6 +32,15 @@ func EncodeFixed(hash [32]byte, size uint64) (string, error) {
|
|||
return multibase.Encode(multibase.Base58BTC, prefixedHash)
|
||||
}
|
||||
|
||||
func EncodeString(hash string, size uint64) (string, error) {
|
||||
hashBytes, err := hex.DecodeString(hash)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return Encode(hashBytes, size)
|
||||
}
|
||||
|
||||
func Valid(cid string) (bool, error) {
|
||||
_, err := maybeDecode(cid)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue