coreapi: object docs
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
Łukasz Magiera committed
Jan 2, 2018 at 21:22 UTC
64e2327e22cd8cffb9c0cc45447d0690ed56aef4
1 file changed
+48
-7
core/coreapi/interface/interface.go
+48
-7
@@ -191,31 +191,72 @@ type KeyAPI interface {
191
Remove(ctx context.Context, name string) (Path, error)
192
}
193
194
-//TODO: Should this use paths instead of cids?
194
+// ObjectAPI specifies the interface to MerkleDAG and contains useful utilities
195
+// for manipulating MerkleDAG data structures.
196
type ObjectAPI interface {
197
+ // New creates new, empty (by default) dag-node.
198
New(context.Context, ...options.ObjectNewOption) (Node, error)
199
+
200
+ // WithType is an option for New which allows to change the type of created
201
+ // dag node.
202
+ //
203
+ // Supported types:
204
+ // * 'empty' - Empty node
205
+ // * 'unixfs-dir' - Empty UnixFS directory
206
WithType(string) options.ObjectNewOption
207
208
+ // Put imports the node into merkledag
209
Put(context.Context, Node) (Path, error)
210
+
211
+ // Get returns the node for the path
212
Get(context.Context, Path) (Node, error)
213
+
214
+ // Data returns reader for data of the node
215
Data(context.Context, Path) (io.Reader, error)
216
+
217
+ // Links returns lint or links the node contains
218
Links(context.Context, Path) ([]*Link, error)
219
+
220
+ // Stat returns information about the node
221
Stat(context.Context, Path) (*ObjectStat, error)
222
223
+ // AddLink adds a link under the specified path. child path can point to a
224
+ // subdirectory within the patent which must be present (can be overridden
225
+ // with WithCreate option).
226
AddLink(ctx context.Context, base Path, name string, child Path, opts ...options.ObjectAddLinkOption) (Node, error)
227
+
228
+ // WithCreate is an option for AddLink which specifies whether create required
229
+ // directories for the child
230
WithCreate(create bool) options.ObjectAddLinkOption
231
208
- RmLink(context.Context, Path, string) (Node, error)
232
+ // RmLink removes a link from the node
233
+ RmLink(ctx context.Context, base Path, link string) (Node, error)
234
+
235
+ // AppendData appends data to the node
236
AppendData(context.Context, Path, io.Reader) (Node, error)
237
+
238
+ // SetData sets the data contained in the node
239
SetData(context.Context, Path, io.Reader) (Node, error)
240
}
241
242
+// ObjectStat provides information about dag nodes
243
type ObjectStat struct {
214
- Cid *cid.Cid
215
- NumLinks int
216
- BlockSize int
217
- LinksSize int
218
- DataSize int
244
+ // Cid is the CID of the node
245
+ Cid *cid.Cid
246
+
247
+ // NumLinks is number of links the node contains
248
+ NumLinks int
249
+
250
+ // BlockSize is size of the raw serialized node
251
+ BlockSize int
252
+
253
+ // LinksSize is size of the links block section
254
+ LinksSize int
255
+
256
+ // DataSize is the size of data block section
257
+ DataSize int
258
+
259
+ // CumulativeSize is size of node
260
CumulativeSize int
261
}
262