coreapi: resolve type/size in Unixfs.Ls
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com> This commit was moved from ipfs/interface-go-ipfs-core@01bbf29cf470532d94aba2bc5a912eb44d9997d0 This commit was moved from ipfs/boxo@54f7855257d69f5f79fe37d7896ddff4e0d1c2f7
Łukasz Magiera committed
Feb 1, 2019 at 23:07 UTC
ef5879661a0feb801ce0463548ca60cf06c9d3a0
2 files changed
+28
-3
core/coreiface/options/unixfs.go
+17
@@ -44,6 +44,9 @@ type UnixfsAddSettings struct {
44
45
type UnixfsLsSettings struct {
46
Async bool
47
+
48
+ ResolveType bool
49
+ ResolveSize bool
50
}
51
52
type UnixfsAddOption func(*UnixfsAddSettings) error
@@ -320,3 +323,17 @@ func (unixfsOpts) Async(async bool) UnixfsLsOption {
323
return nil
324
}
325
}
326
+
327
+func (unixfsOpts) ResolveSize(resolve bool) UnixfsLsOption {
328
+ return func(settings *UnixfsLsSettings) error {
329
+ settings.ResolveSize = resolve
330
+ return nil
331
+ }
332
+}
333
+
334
+func (unixfsOpts) ResolveType(resolve bool) UnixfsLsOption {
335
+ return func(settings *UnixfsLsSettings) error {
336
+ settings.ResolveSize = resolve
337
+ return nil
338
+ }
339
+}
\ No newline at end of file
core/coreiface/unixfs.go
+11
-3
@@ -2,10 +2,10 @@ package iface
2
3
import (
4
"context"
5
-
5
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
6
8
- ft "gx/ipfs/QmQ1JnYpnzkaurjW1yxkQxC2w3K1PorNE1nv1vaP5Le7sq/go-unixfs"
7
+ "gx/ipfs/QmQ1JnYpnzkaurjW1yxkQxC2w3K1PorNE1nv1vaP5Le7sq/go-unixfs/pb"
8
+ ipld "gx/ipfs/QmRL22E4paat7ky7vx9MLpR97JHHbFPrg3ytFQw6qp1y1s/go-ipld-format"
9
"gx/ipfs/QmaXvvAVAQ5ABqM5xtjYmV85xmN5MkWAZsX9H9Fwo4FVXp/go-ipfs-files"
10
)
11
@@ -16,6 +16,14 @@ type AddEvent struct {
16
Size string `json:",omitempty"`
17
}
18
19
+type LsLink struct {
20
+ Link *ipld.Link
21
+ Size uint64
22
+ Type unixfs_pb.Data_DataType
23
+
24
+ Err error
25
+}
26
+
27
// UnixfsAPI is the basic interface to immutable files in IPFS
28
// NOTE: This API is heavily WIP, things are guaranteed to break frequently
29
type UnixfsAPI interface {
@@ -31,5 +39,5 @@ type UnixfsAPI interface {
39
Get(context.Context, Path) (files.Node, error)
40
41
// Ls returns the list of links in a directory
34
- Ls(context.Context, Path, ...options.UnixfsLsOption) (<-chan ft.LinkResult, error)
42
+ Ls(context.Context, Path, ...options.UnixfsLsOption) (<-chan LsLink, error)
43
}