coreapi unixfs: progress events

License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>


This commit was moved from ipfs/interface-go-ipfs-core@df1797113e

This commit was moved from ipfs/boxo@56ef5340a3
This commit is contained in:
Łukasz Magiera 2018-10-04 01:00:26 +02:00
parent 48761861ca
commit be5cccd21a
2 changed files with 44 additions and 0 deletions

View File

@ -35,6 +35,10 @@ type UnixfsAddSettings struct {
Wrap bool
Hidden bool
StdinName string
Events chan<- interface{}
Silent bool
Progress bool
}
type UnixfsAddOption func(*UnixfsAddSettings) error
@ -59,6 +63,10 @@ func UnixfsAddOptions(opts ...UnixfsAddOption) (*UnixfsAddSettings, cid.Prefix,
Wrap: false,
Hidden: false,
StdinName: "",
Events: nil,
Silent: false,
Progress: false,
}
for _, opt := range opts {
@ -236,3 +244,30 @@ func (unixfsOpts) StdinName(name string) UnixfsAddOption {
return nil
}
}
// Events specifies channel which will be used to report events about ongoing
// Add operation.
//
// Note that if this channel blocks it may slowdown the adder
func (unixfsOpts) Events(sink chan<- interface{}) UnixfsAddOption {
return func(settings *UnixfsAddSettings) error {
settings.Events = sink
return nil
}
}
// Silent reduces event output
func (unixfsOpts) Silent(silent bool) UnixfsAddOption {
return func(settings *UnixfsAddSettings) error {
settings.Silent = silent
return nil
}
}
// Progress tells the adder whether to enable progress events
func (unixfsOpts) Progress(enable bool) UnixfsAddOption {
return func(settings *UnixfsAddSettings) error {
settings.Progress = enable
return nil
}
}

View File

@ -9,6 +9,14 @@ import (
ipld "gx/ipfs/QmdDXJs4axxefSPgK6Y1QhpJWKuDPnGJiqgq4uncb4rFHL/go-ipld-format"
)
// TODO: ideas on making this more coreapi-ish without breaking the http API?
type AddEvent struct {
Name string
Hash string `json:",omitempty"`
Bytes int64 `json:",omitempty"`
Size string `json:",omitempty"`
}
// UnixfsAPI is the basic interface to immutable files in IPFS
// NOTE: This API is heavily WIP, things are guaranteed to break frequently
type UnixfsAPI interface {
@ -24,6 +32,7 @@ type UnixfsAPI interface {
Get(context.Context, Path) (files.File, error)
// Cat returns a reader for the file
// TODO: Remove in favour of Get (if we use Get on a file we still have reader directly, so..)
Cat(context.Context, Path) (Reader, error)
// Ls returns the list of links in a directory