Add simple utility to convert from one base to another.
This commit is contained in:
committed by
Jakub Sztandera
parent
158b7d8e3c
commit
7e9a23df22
32
multibase-conv/main.go
Normal file
32
multibase-conv/main.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
multibase "github.com/multiformats/go-multibase"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) != 3 {
|
||||
fmt.Printf("usage: %s CID NEW-BASE\n", os.Args[0])
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
cid := os.Args[1]
|
||||
newBase := os.Args[2]
|
||||
|
||||
_, data, err := multibase.Decode(cid)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
newCid, err := multibase.Encode(multibase.Encoding(newBase[0]), data)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Printf("%s\n", newCid)
|
||||
}
|
||||
Reference in New Issue
Block a user