@cryptotaxi247 / kubo / commits / be5cccd21

coreapi unixfs: progress events

License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com> This commit was moved from ipfs/interface-go-ipfs-core@df1797113e1dc062a9e53af11b8ea4268c855ef9 This commit was moved from ipfs/boxo@56ef5340a321a06604f4f98efcba4da03b6a4358

Łukasz Magiera committed Oct 4, 2018 at 01:00 UTC be5cccd21ac577b26638e777d189a9f27df79058
2 files changed +44
core/coreiface/options/unixfs.go
+35
@@ -35,6 +35,10 @@ type UnixfsAddSettings struct {
35 Wrap bool
36 Hidden bool
37 StdinName string
38 +
39 + Events chan<- interface{}
40 + Silent bool
41 + Progress bool
42 }
43
44 type UnixfsAddOption func(*UnixfsAddSettings) error
@@ -59,6 +63,10 @@ func UnixfsAddOptions(opts ...UnixfsAddOption) (*UnixfsAddSettings, cid.Prefix,
63 Wrap: false,
64 Hidden: false,
65 StdinName: "",
66 +
67 + Events: nil,
68 + Silent: false,
69 + Progress: false,
70 }
71
72 for _, opt := range opts {
@@ -236,3 +244,30 @@ func (unixfsOpts) StdinName(name string) UnixfsAddOption {
244 return nil
245 }
246 }
247 +
248 +// Events specifies channel which will be used to report events about ongoing
249 +// Add operation.
250 +//
251 +// Note that if this channel blocks it may slowdown the adder
252 +func (unixfsOpts) Events(sink chan<- interface{}) UnixfsAddOption {
253 + return func(settings *UnixfsAddSettings) error {
254 + settings.Events = sink
255 + return nil
256 + }
257 +}
258 +
259 +// Silent reduces event output
260 +func (unixfsOpts) Silent(silent bool) UnixfsAddOption {
261 + return func(settings *UnixfsAddSettings) error {
262 + settings.Silent = silent
263 + return nil
264 + }
265 +}
266 +
267 +// Progress tells the adder whether to enable progress events
268 +func (unixfsOpts) Progress(enable bool) UnixfsAddOption {
269 + return func(settings *UnixfsAddSettings) error {
270 + settings.Progress = enable
271 + return nil
272 + }
273 +}
core/coreiface/unixfs.go
+9
@@ -9,6 +9,14 @@ import (
9 ipld "gx/ipfs/QmdDXJs4axxefSPgK6Y1QhpJWKuDPnGJiqgq4uncb4rFHL/go-ipld-format"
10 )
11
12 +// TODO: ideas on making this more coreapi-ish without breaking the http API?
13 +type AddEvent struct {
14 + Name string
15 + Hash string `json:",omitempty"`
16 + Bytes int64 `json:",omitempty"`
17 + Size string `json:",omitempty"`
18 +}
19 +
20 // UnixfsAPI is the basic interface to immutable files in IPFS
21 // NOTE: This API is heavily WIP, things are guaranteed to break frequently
22 type UnixfsAPI interface {
@@ -24,6 +32,7 @@ type UnixfsAPI interface {
32 Get(context.Context, Path) (files.File, error)
33
34 // Cat returns a reader for the file
35 + // TODO: Remove in favour of Get (if we use Get on a file we still have reader directly, so..)
36 Cat(context.Context, Path) (Reader, error)
37
38 // Ls returns the list of links in a directory