@cryptotaxi247 / kubo / commits / 0a01ffb87

ipfs add: added size to response of `ipfs add` command

The `ipfs add` command was modified to include the added node's size as a string. The size is included in the dagnode info sent over the output channel. License: MIT Signed-off-by: Tom O'Donnell <todonnel91@gmail.com>

Tom O'Donnell (te0d) committed Jul 19, 2017 at 17:32 UTC 0a01ffb87fa7a142e577cf795e2976d679ec2fac
1 file changed +9
core/coreunix/add.go
+9
@@ -7,6 +7,7 @@ import (
7 "io/ioutil"
8 "os"
9 gopath "path"
10 + "strconv"
11
12 bs "github.com/ipfs/go-ipfs/blocks/blockstore"
13 bstore "github.com/ipfs/go-ipfs/blocks/blockstore"
@@ -46,6 +47,7 @@ type Link struct {
47 type Object struct {
48 Hash string
49 Links []Link
50 + Size string
51 }
52
53 type hiddenFileError struct {
@@ -68,6 +70,7 @@ type AddedObject struct {
70 Name string
71 Hash string `json:",omitempty"`
72 Bytes int64 `json:",omitempty"`
73 + Size string `json:",omitempty"`
74 }
75
76 func NewAdder(ctx context.Context, p pin.Pinner, bs bstore.GCBlockstore, ds dag.DAGService) (*Adder, error) {
@@ -543,6 +546,7 @@ func outputDagnode(out chan interface{}, name string, dn node.Node) error {
546 out <- &AddedObject{
547 Hash: o.Hash,
548 Name: name,
549 + Size: o.Size,
550 }
551
552 return nil
@@ -558,9 +562,14 @@ func NewMemoryDagService() dag.DAGService {
562 // from core/commands/object.go
563 func getOutput(dagnode node.Node) (*Object, error) {
564 c := dagnode.Cid()
565 + s, err := dagnode.Size()
566 + if err != nil {
567 + return nil, err
568 + }
569
570 output := &Object{
571 Hash: c.String(),
572 + Size: strconv.FormatUint(s, 10),
573 Links: make([]Link, len(dagnode.Links())),
574 }
575