coreapi: draft block API
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
Łukasz Magiera committed
Jan 5, 2018 at 01:50 UTC
219eae76143d7171721239a57e2a3e03be6911d4
2 files changed
+32
core/coreapi/interface/interface.go
+18
@@ -53,6 +53,11 @@ type Key interface {
53
Path() Path
54
}
55
56
+type BlockStat interface {
57
+ Size() int
58
+ Path() Path
59
+}
60
+
61
// CoreAPI defines an unified interface to IPFS for Go programs.
62
type CoreAPI interface {
63
// Unixfs returns an implementation of Unixfs API.
@@ -87,6 +92,19 @@ type UnixfsAPI interface {
92
Ls(context.Context, Path) ([]*Link, error)
93
}
94
95
+type BlockAPI interface {
96
+ Put(context.Context, io.Reader) (Path, error)
97
+ WithCodec(codec uint64) options.BlockPutOption
98
+ WithHash(mhType uint64, mhLen int) options.BlockPutOption
99
+
100
+ Get(context.Context) (io.Reader, error)
101
+
102
+ Rm(context.Context) error
103
+ WithForce(force bool) options.BlockRmOption
104
+
105
+ Stat(context.Context) (BlockStat, error)
106
+}
107
+
108
// DagAPI specifies the interface to IPLD
109
type DagAPI interface {
110
// Put inserts data using specified format and input encoding.
core/coreapi/interface/options/block.go
new
+14
@@ -0,0 +1,14 @@
1
+package options
2
+
3
+type BlockPutSettings struct {
4
+ Codec uint64
5
+ MhType uint64
6
+ MhLength int
7
+}
8
+
9
+type BlockRmSettings struct {
10
+ Force bool
11
+}
12
+
13
+type BlockPutOption func(*BlockPutSettings) error
14
+type BlockRmOption func(*BlockRmSettings) error