ipfs object has learned stat
'ipfs object stat' is a plumbing command to print DAG node statistics. <key> is a base58 encoded multihash. It outputs to stdout: NumLinks int number of links in link table BlockSize int size of the raw, encoded data LinksSize int size of the links segment DataSize int size of the data segment CumulativeSize int cumulative size of object and references
Juan Batiz-Benet committed
Jan 7, 2015 at 02:30 UTC
6b2795338f918c9e6bf1ca4dc864b50fcaa7bafb
2 files changed
+63
-2
core/commands/object.go
+61
@@ -4,6 +4,7 @@ import (
4
"bytes"
5
"encoding/json"
6
"errors"
7
+ "fmt"
8
"io"
9
"io/ioutil"
10
"strings"
@@ -36,6 +37,7 @@ ipfs object get <key> - Get the DAG node named by <key>
37
ipfs object put <data> <encoding> - Stores input, outputs its key
38
ipfs object data <key> - Outputs raw bytes in an object
39
ipfs object links <key> - Outputs links pointed to by object
40
+ipfs object stat <key> - Outputs statistics of object
41
`,
42
},
43
@@ -44,6 +46,7 @@ ipfs object links <key> - Outputs links pointed to by object
46
"links": objectLinksCmd,
47
"get": objectGetCmd,
48
"put": objectPutCmd,
49
+ "stat": objectStatCmd,
50
},
51
}
52
@@ -180,6 +183,64 @@ This command outputs data in the following encodings:
183
},
184
}
185
186
+var objectStatCmd = &cmds.Command{
187
+ Helptext: cmds.HelpText{
188
+ Tagline: "Get stats for the DAG node named by <key>",
189
+ ShortDescription: `
190
+'ipfs object stat' is a plumbing command to print DAG node statistics.
191
+<key> is a base58 encoded multihash. It outputs to stdout:
192
+
193
+ NumLinks int number of links in link table
194
+ BlockSize int size of the raw, encoded data
195
+ LinksSize int size of the links segment
196
+ DataSize int size of the data segment
197
+ CumulativeSize int cumulative size of object and its references
198
+`,
199
+ },
200
+
201
+ Arguments: []cmds.Argument{
202
+ cmds.StringArg("key", true, false, "Key of the object to retrieve (in base58-encoded multihash format)"),
203
+ },
204
+ Run: func(req cmds.Request) (interface{}, error) {
205
+ n, err := req.Context().GetNode()
206
+ if err != nil {
207
+ return nil, err
208
+ }
209
+
210
+ key := req.Arguments()[0]
211
+
212
+ object, err := objectGet(n, key)
213
+ if err != nil {
214
+ return nil, err
215
+ }
216
+
217
+ ns, err := object.Stat()
218
+ if err != nil {
219
+ return nil, err
220
+ }
221
+
222
+ return ns, nil
223
+ },
224
+ Type: dag.NodeStat{},
225
+ Marshalers: cmds.MarshalerMap{
226
+ cmds.Text: func(res cmds.Response) (io.Reader, error) {
227
+ ns := res.Output().(dag.NodeStat)
228
+
229
+ var buf bytes.Buffer
230
+ w := func(s string, n int) {
231
+ buf.Write([]byte(fmt.Sprintf("%s: %d\n", s, n)))
232
+ }
233
+ w("NumLinks", ns.NumLinks)
234
+ w("BlockSize", ns.BlockSize)
235
+ w("LinksSize", ns.LinksSize)
236
+ w("DataSize", ns.DataSize)
237
+ w("CumulativeSize", ns.CumulativeSize)
238
+
239
+ return &buf, nil
240
+ },
241
+ },
242
+}
243
+
244
var objectPutCmd = &cmds.Command{
245
Helptext: cmds.HelpText{
246
Tagline: "Stores input as a DAG object, outputs its key",
merkledag/node.go
+2
-2
@@ -27,10 +27,10 @@ type Node struct {
27
// NodeStat is a statistics object for a Node. Mostly sizes.
28
type NodeStat struct {
29
NumLinks int // number of links in link table
30
- BlockSize int // size of the raw data
30
+ BlockSize int // size of the raw, encoded data
31
LinksSize int // size of the links segment
32
DataSize int // size of the data segment
33
- CumulativeSize int // cumulatie size of object + all it references
33
+ CumulativeSize int // cumulative size of object and its references
34
}
35
36
func (ns NodeStat) String() string {