Commit df179711 authored by Łukasz Magiera's avatar Łukasz Magiera

coreapi unixfs: progress events

License: MIT
Signed-off-by: default avatarŁukasz Magiera <magik6k@gmail.com>
parent aa7a8776
...@@ -35,6 +35,10 @@ type UnixfsAddSettings struct { ...@@ -35,6 +35,10 @@ type UnixfsAddSettings struct {
Wrap bool Wrap bool
Hidden bool Hidden bool
StdinName string StdinName string
Events chan<- interface{}
Silent bool
Progress bool
} }
type UnixfsAddOption func(*UnixfsAddSettings) error type UnixfsAddOption func(*UnixfsAddSettings) error
...@@ -59,6 +63,10 @@ func UnixfsAddOptions(opts ...UnixfsAddOption) (*UnixfsAddSettings, cid.Prefix, ...@@ -59,6 +63,10 @@ func UnixfsAddOptions(opts ...UnixfsAddOption) (*UnixfsAddSettings, cid.Prefix,
Wrap: false, Wrap: false,
Hidden: false, Hidden: false,
StdinName: "", StdinName: "",
Events: nil,
Silent: false,
Progress: false,
} }
for _, opt := range opts { for _, opt := range opts {
...@@ -236,3 +244,30 @@ func (unixfsOpts) StdinName(name string) UnixfsAddOption { ...@@ -236,3 +244,30 @@ func (unixfsOpts) StdinName(name string) UnixfsAddOption {
return nil 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
}
}
...@@ -9,6 +9,14 @@ import ( ...@@ -9,6 +9,14 @@ import (
ipld "gx/ipfs/QmdDXJs4axxefSPgK6Y1QhpJWKuDPnGJiqgq4uncb4rFHL/go-ipld-format" 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 // UnixfsAPI is the basic interface to immutable files in IPFS
// NOTE: This API is heavily WIP, things are guaranteed to break frequently // NOTE: This API is heavily WIP, things are guaranteed to break frequently
type UnixfsAPI interface { type UnixfsAPI interface {
...@@ -24,6 +32,7 @@ type UnixfsAPI interface { ...@@ -24,6 +32,7 @@ type UnixfsAPI interface {
Get(context.Context, Path) (files.File, error) Get(context.Context, Path) (files.File, error)
// Cat returns a reader for the file // 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) Cat(context.Context, Path) (Reader, error)
// Ls returns the list of links in a directory // Ls returns the list of links in a directory
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment