Commit e8ed89ce authored by Steven Allen's avatar Steven Allen

make code-climate happier

License: MIT
Signed-off-by: default avatarSteven Allen <steven@stebalien.com>
parent 3ef1c87d
...@@ -66,6 +66,7 @@ type child interface { ...@@ -66,6 +66,7 @@ type child interface {
Label() string Label() string
} }
// NewHamtShard creates a new, empty HAMT shard with the given size.
func NewHamtShard(dserv node.DAGService, size int) (*HamtShard, error) { func NewHamtShard(dserv node.DAGService, size int) (*HamtShard, error) {
ds, err := makeHamtShard(dserv, size) ds, err := makeHamtShard(dserv, size)
if err != nil { if err != nil {
...@@ -93,6 +94,7 @@ func makeHamtShard(ds node.DAGService, size int) (*HamtShard, error) { ...@@ -93,6 +94,7 @@ func makeHamtShard(ds node.DAGService, size int) (*HamtShard, error) {
}, nil }, nil
} }
// NewHamtFromDag creates new a HAMT shard from the given DAG.
func NewHamtFromDag(dserv node.DAGService, nd node.Node) (*HamtShard, error) { func NewHamtFromDag(dserv node.DAGService, nd node.Node) (*HamtShard, error) {
pbnd, ok := nd.(*dag.ProtoNode) pbnd, ok := nd.(*dag.ProtoNode)
if !ok { if !ok {
......
...@@ -51,6 +51,8 @@ func NewDirectory(dserv node.DAGService) *Directory { ...@@ -51,6 +51,8 @@ func NewDirectory(dserv node.DAGService) *Directory {
// ErrNotADir implies that the given node was not a unixfs directory // ErrNotADir implies that the given node was not a unixfs directory
var ErrNotADir = fmt.Errorf("merkledag node was not a directory or shard") var ErrNotADir = fmt.Errorf("merkledag node was not a directory or shard")
// NewDirectoryFromNode loads a unixfs directory from the given IPLD node and
// DAGService.
func NewDirectoryFromNode(dserv node.DAGService, nd node.Node) (*Directory, error) { func NewDirectoryFromNode(dserv node.DAGService, nd node.Node) (*Directory, error) {
pbnd, ok := nd.(*mdag.ProtoNode) pbnd, ok := nd.(*mdag.ProtoNode)
if !ok { if !ok {
......
...@@ -50,6 +50,7 @@ type pbDagReader struct { ...@@ -50,6 +50,7 @@ type pbDagReader struct {
var _ DagReader = (*pbDagReader)(nil) var _ DagReader = (*pbDagReader)(nil)
// NewPBFileReader constructs a new PBFileReader.
func NewPBFileReader(ctx context.Context, n *mdag.ProtoNode, pb *ftpb.Data, serv node.DAGService) *pbDagReader { func NewPBFileReader(ctx context.Context, n *mdag.ProtoNode, pb *ftpb.Data, serv node.DAGService) *pbDagReader {
fctx, cancel := context.WithCancel(ctx) fctx, cancel := context.WithCancel(ctx)
curLinks := getLinkCids(n) curLinks := getLinkCids(n)
......
...@@ -27,6 +27,7 @@ func SizeSplitterGen(size int64) chunk.SplitterGen { ...@@ -27,6 +27,7 @@ func SizeSplitterGen(size int64) chunk.SplitterGen {
} }
} }
// GetDAGServ returns a mock DAGService.
func GetDAGServ() node.DAGService { func GetDAGServ() node.DAGService {
return mdagmock.Mock() return mdagmock.Mock()
} }
...@@ -51,6 +52,7 @@ func init() { ...@@ -51,6 +52,7 @@ func init() {
UseBlake2b256.Prefix.MhLength = -1 UseBlake2b256.Prefix.MhLength = -1
} }
// GetNode returns a unixfs file node with the specified data.
func GetNode(t testing.TB, dserv node.DAGService, data []byte, opts NodeOpts) node.Node { func GetNode(t testing.TB, dserv node.DAGService, data []byte, opts NodeOpts) node.Node {
in := bytes.NewReader(data) in := bytes.NewReader(data)
...@@ -69,10 +71,12 @@ func GetNode(t testing.TB, dserv node.DAGService, data []byte, opts NodeOpts) no ...@@ -69,10 +71,12 @@ func GetNode(t testing.TB, dserv node.DAGService, data []byte, opts NodeOpts) no
return node return node
} }
// GetEmptyNode returns an empty unixfs file node.
func GetEmptyNode(t testing.TB, dserv node.DAGService, opts NodeOpts) node.Node { func GetEmptyNode(t testing.TB, dserv node.DAGService, opts NodeOpts) node.Node {
return GetNode(t, dserv, []byte{}, opts) return GetNode(t, dserv, []byte{}, opts)
} }
// GetRandomNode returns a random unixfs file node.
func GetRandomNode(t testing.TB, dserv node.DAGService, size int64, opts NodeOpts) ([]byte, node.Node) { func GetRandomNode(t testing.TB, dserv node.DAGService, size int64, opts NodeOpts) ([]byte, node.Node) {
in := io.LimitReader(u.NewTimeSeededRand(), size) in := io.LimitReader(u.NewTimeSeededRand(), size)
buf, err := ioutil.ReadAll(in) buf, err := ioutil.ReadAll(in)
...@@ -96,6 +100,7 @@ func ArrComp(a, b []byte) error { ...@@ -96,6 +100,7 @@ func ArrComp(a, b []byte) error {
return nil return nil
} }
// PrintDag pretty-prints the given dag to stdout.
func PrintDag(nd *mdag.ProtoNode, ds node.DAGService, indent int) { func PrintDag(nd *mdag.ProtoNode, ds node.DAGService, indent int) {
pbd, err := ft.FromBytes(nd.Data()) pbd, err := ft.FromBytes(nd.Data())
if err != nil { if err != nil {
......
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