container: I/O as strings for base64
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"iter"
|
"iter"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
"github.com/ipld/go-ipld-prime"
|
"github.com/ipld/go-ipld-prime"
|
||||||
@@ -151,8 +152,8 @@ func FromCborReader(r io.Reader) (Reader, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FromCborBase64 decodes a base64 DAG-CBOR encoded container.
|
// FromCborBase64 decodes a base64 DAG-CBOR encoded container.
|
||||||
func FromCborBase64(data []byte) (Reader, error) {
|
func FromCborBase64(data string) (Reader, error) {
|
||||||
return FromCborBase64Reader(bytes.NewReader(data))
|
return FromCborBase64Reader(strings.NewReader(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
// FromCborBase64Reader is the same as FromCborBase64, but with an io.Reader.
|
// FromCborBase64Reader is the same as FromCborBase64, but with an io.Reader.
|
||||||
@@ -189,8 +190,8 @@ func FromCarReader(r io.Reader) (Reader, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FromCarBase64 decodes a base64 CAR file encoded container.
|
// FromCarBase64 decodes a base64 CAR file encoded container.
|
||||||
func FromCarBase64(data []byte) (Reader, error) {
|
func FromCarBase64(data string) (Reader, error) {
|
||||||
return FromCarReader(bytes.NewReader(data))
|
return FromCarReader(strings.NewReader(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
// FromCarBase64Reader is the same as FromCarBase64, but with an io.Reader.
|
// FromCarBase64Reader is the same as FromCarBase64, but with an io.Reader.
|
||||||
|
|||||||
@@ -53,13 +53,13 @@ func (ctn Writer) ToCborWriter(w io.Writer) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ToCborBase64 encode the container into a base64 encoded DAG-CBOR binary format.
|
// ToCborBase64 encode the container into a base64 encoded DAG-CBOR binary format.
|
||||||
func (ctn Writer) ToCborBase64() ([]byte, error) {
|
func (ctn Writer) ToCborBase64() (string, error) {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
err := ctn.ToCborBase64Writer(&buf)
|
err := ctn.ToCborBase64Writer(&buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return "", err
|
||||||
}
|
}
|
||||||
return buf.Bytes(), nil
|
return buf.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToCborBase64Writer is the same as ToCborBase64, but with an io.Writer.
|
// ToCborBase64Writer is the same as ToCborBase64, but with an io.Writer.
|
||||||
@@ -91,13 +91,13 @@ func (ctn Writer) ToCarWriter(w io.Writer) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ToCarBase64 encode the container into a base64 encoded CAR file.
|
// ToCarBase64 encode the container into a base64 encoded CAR file.
|
||||||
func (ctn Writer) ToCarBase64() ([]byte, error) {
|
func (ctn Writer) ToCarBase64() (string, error) {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
err := ctn.ToCarBase64Writer(&buf)
|
err := ctn.ToCarBase64Writer(&buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return "", err
|
||||||
}
|
}
|
||||||
return buf.Bytes(), nil
|
return buf.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToCarBase64Writer is the same as ToCarBase64, but with an io.Writer.
|
// ToCarBase64Writer is the same as ToCarBase64, but with an io.Writer.
|
||||||
|
|||||||
Reference in New Issue
Block a user