dagmodifer: refactor appendData method
License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>
Kevin Atkinson committed
Jun 21, 2017 at 00:49 UTC
3f6a7b7b817ffb6c645eace0bc8f8f2d2fc8911f
1 file changed
+6
-12
unixfs/mod/dagmodifier.go
+6
-12
@@ -151,6 +151,7 @@ func (dm *DagModifier) Write(b []byte) (int, error) {
151
152
var ErrNoRawYet = fmt.Errorf("currently only fully support protonodes in the dagmodifier")
153
154
+// Size returns the Filesize of the node
155
func (dm *DagModifier) Size() (int64, error) {
156
switch nd := dm.curNode.(type) {
157
case *mdag.ProtoNode:
@@ -321,25 +322,18 @@ func (dm *DagModifier) modifyDag(n node.Node, offset uint64, data io.Reader) (*c
322
323
// appendData appends the blocks from the given chan to the end of this dag
324
func (dm *DagModifier) appendData(nd node.Node, spl chunk.Splitter) (node.Node, error) {
324
-
325
- var root *mdag.ProtoNode
325
switch nd := nd.(type) {
326
case *mdag.ProtoNode:
328
- root = nd
327
+ dbp := &help.DagBuilderParams{
328
+ Dagserv: dm.dagserv,
329
+ Maxlinks: help.DefaultLinksPerBlock,
330
+ }
331
+ return trickle.TrickleAppend(dm.ctx, nd, dbp.New(spl))
332
case *mdag.RawNode:
330
- // TODO: be able to append to rawnodes. Probably requires making this
331
- // node a child of a unxifs intermediate node and passing it down
333
return nil, fmt.Errorf("appending to raw node types not yet supported")
334
default:
335
return nil, ErrNotUnixfs
336
}
336
-
337
- dbp := &help.DagBuilderParams{
338
- Dagserv: dm.dagserv,
339
- Maxlinks: help.DefaultLinksPerBlock,
340
- }
341
-
342
- return trickle.TrickleAppend(dm.ctx, root, dbp.New(spl))
337
}
338
339
// Read data from this dag starting at the current offset