coreapi: object API tests
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com> This commit was moved from ipfs/interface-go-ipfs-core@858d49b07c296b36a58fa4d4469f5e08a9f9b5e7 This commit was moved from ipfs/boxo@d878d812272fc70b7e3e799f139056885dab474f
Łukasz Magiera committed
Jan 5, 2018 at 01:13 UTC
a8a84d5b1bc8125a5113e80b994193e8f3fab9de
2 files changed
+22
-5
core/coreiface/interface.go
+13
-5
@@ -219,6 +219,14 @@ type ObjectAPI interface {
219
// * "json"
220
WithInputEnc(e string) options.ObjectPutOption
221
222
+ // WithDataType specifies the encoding of data field when using Josn or XML
223
+ // input encoding.
224
+ //
225
+ // Supported types:
226
+ // * "text" (default)
227
+ // * "base64"
228
+ WithDataType(t string) options.ObjectPutOption
229
+
230
// Get returns the node for the path
231
Get(context.Context, Path) (Node, error)
232
@@ -234,20 +242,20 @@ type ObjectAPI interface {
242
// AddLink adds a link under the specified path. child path can point to a
243
// subdirectory within the patent which must be present (can be overridden
244
// with WithCreate option).
237
- AddLink(ctx context.Context, base Path, name string, child Path, opts ...options.ObjectAddLinkOption) (Node, error)
245
+ AddLink(ctx context.Context, base Path, name string, child Path, opts ...options.ObjectAddLinkOption) (Path, error)
246
247
// WithCreate is an option for AddLink which specifies whether create required
248
// directories for the child
249
WithCreate(create bool) options.ObjectAddLinkOption
250
251
// RmLink removes a link from the node
244
- RmLink(ctx context.Context, base Path, link string) (Node, error)
252
+ RmLink(ctx context.Context, base Path, link string) (Path, error)
253
254
// AppendData appends data to the node
247
- AppendData(context.Context, Path, io.Reader) (Node, error)
255
+ AppendData(context.Context, Path, io.Reader) (Path, error)
256
257
// SetData sets the data contained in the node
250
- SetData(context.Context, Path, io.Reader) (Node, error)
258
+ SetData(context.Context, Path, io.Reader) (Path, error)
259
}
260
261
// ObjectStat provides information about dag nodes
@@ -267,7 +275,7 @@ type ObjectStat struct {
275
// DataSize is the size of data block section
276
DataSize int
277
270
- // CumulativeSize is size of node
278
+ // CumulativeSize is size of the tree (BlockSize + link sizes)
279
CumulativeSize int
280
}
281
core/coreiface/options/object.go
+9
@@ -6,6 +6,7 @@ type ObjectNewSettings struct {
6
7
type ObjectPutSettings struct {
8
InputEnc string
9
+ DataType string
10
}
11
12
type ObjectAddLinkSettings struct {
@@ -33,6 +34,7 @@ func ObjectNewOptions(opts ...ObjectNewOption) (*ObjectNewSettings, error) {
34
func ObjectPutOptions(opts ...ObjectPutOption) (*ObjectPutSettings, error) {
35
options := &ObjectPutSettings{
36
InputEnc: "json",
37
+ DataType: "text",
38
}
39
40
for _, opt := range opts {
@@ -74,6 +76,13 @@ func (api *ObjectOptions) WithInputEnc(e string) ObjectPutOption {
76
}
77
}
78
79
+func (api *ObjectOptions) WithDataType(t string) ObjectPutOption {
80
+ return func(settings *ObjectPutSettings) error {
81
+ settings.DataType = t
82
+ return nil
83
+ }
84
+}
85
+
86
func (api *ObjectOptions) WithCreate(create bool) ObjectAddLinkOption {
87
return func(settings *ObjectAddLinkSettings) error {
88
settings.Create = create