ipld-eth-server/vendor/github.com/ipfs/go-ipld-cbor/readable.go
Elizabeth Engelman 36533f7c3f Update vendor directory and make necessary code changes
Fixes for new geth version
2019-09-25 16:32:27 -05:00

34 lines
629 B
Go

package cbornode
import (
"bufio"
"bytes"
cbor "github.com/polydawn/refmt/cbor"
"github.com/polydawn/refmt/pretty"
"github.com/polydawn/refmt/shared"
)
//HumanReadable returns a string representation of a CBOR blob
func HumanReadable(blob []byte) (string, error) {
reader := bytes.NewReader(blob)
var buf bytes.Buffer
writer := bufio.NewWriter(&buf)
err := shared.TokenPump{
TokenSource: cbor.NewDecoder(cbor.DecodeOptions{}, reader),
TokenSink: pretty.NewEncoder(writer),
}.Run()
if err != nil {
return "", err
}
if err = writer.Flush(); err != nil {
return "", err
}
return buf.String(), nil
}