Commit 8bb45fda authored by Hector Sanjuan's avatar Hector Sanjuan

Golint: make BufDagReader public

License: MIT
Signed-off-by: default avatarHector Sanjuan <hector@protocol.ai>
parent ca4271b7
......@@ -6,27 +6,32 @@ import (
"io"
)
type bufDagReader struct {
// BufDagReader implements a DagReader that reads from a byte slice
// using a bytes.Reader. It is used for RawNodes.
type BufDagReader struct {
*bytes.Reader
}
// newBufDagReader returns a DAG reader for the given byte slice.
// NewBufDagReader returns a DAG reader for the given byte slice.
// BufDagReader is used to read RawNodes.
func newBufDagReader(b []byte) *bufDagReader {
return &bufDagReader{bytes.NewReader(b)}
func NewBufDagReader(b []byte) *BufDagReader {
return &BufDagReader{bytes.NewReader(b)}
}
var _ DagReader = (*bufDagReader)(nil)
var _ DagReader = (*BufDagReader)(nil)
func (*bufDagReader) Close() error {
// Close is a nop.
func (*BufDagReader) Close() error {
return nil
}
func (rd *bufDagReader) CtxReadFull(ctx context.Context, b []byte) (int, error) {
// CtxReadFull reads the slice onto b.
func (rd *BufDagReader) CtxReadFull(ctx context.Context, b []byte) (int, error) {
return rd.Read(b)
}
func (rd *bufDagReader) Offset() int64 {
// Offset returns the current offset.
func (rd *BufDagReader) Offset() int64 {
of, err := rd.Seek(0, io.SeekCurrent)
if err != nil {
panic("this should never happen " + err.Error())
......@@ -34,7 +39,8 @@ func (rd *bufDagReader) Offset() int64 {
return of
}
func (rd *bufDagReader) Size() uint64 {
// Size returns the size of the buffer.
func (rd *BufDagReader) Size() uint64 {
s := rd.Reader.Size()
if s < 0 {
panic("size smaller than 0 (impossible!!)")
......
......@@ -43,7 +43,7 @@ type ReadSeekCloser interface {
func NewDagReader(ctx context.Context, n ipld.Node, serv ipld.NodeGetter) (DagReader, error) {
switch n := n.(type) {
case *mdag.RawNode:
return newBufDagReader(n.RawData()), nil
return NewBufDagReader(n.RawData()), nil
case *mdag.ProtoNode:
pb := new(ftpb.Data)
if err := proto.Unmarshal(n.Data(), pb); err != nil {
......
......@@ -57,7 +57,7 @@ func NewPBFileReader(ctx context.Context, n *mdag.ProtoNode, pb *ftpb.Data, serv
return &PBDagReader{
node: n,
serv: serv,
buf: newBufDagReader(pb.GetData()),
buf: NewBufDagReader(pb.GetData()),
promises: make([]*ipld.NodePromise, len(curLinks)),
links: curLinks,
ctx: fctx,
......@@ -119,7 +119,7 @@ func (dr *PBDagReader) precalcNextBuf(ctx context.Context) error {
dr.buf = NewPBFileReader(dr.ctx, nxt, pb, dr.serv)
return nil
case ftpb.Data_Raw:
dr.buf = newBufDagReader(pb.GetData())
dr.buf = NewBufDagReader(pb.GetData())
return nil
case ftpb.Data_Metadata:
return errors.New("shouldnt have had metadata object inside file")
......@@ -256,7 +256,7 @@ func (dr *PBDagReader) Seek(offset int64, whence int) (int64, error) {
if dr.buf != nil {
dr.buf.Close()
}
dr.buf = newBufDagReader(pb.GetData()[offset:])
dr.buf = NewBufDagReader(pb.GetData()[offset:])
// start reading links from the beginning
dr.linkPosition = 0
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment