mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-10 10:47:51 +08:00
add context to files reading
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
parent
b4a47e35db
commit
b078915fb4
@ -374,7 +374,7 @@ Examples:
|
||||
res.SetError(err, cmds.ErrNormal)
|
||||
return
|
||||
}
|
||||
var r io.Reader = fi
|
||||
var r io.Reader = &contextReaderWrapper{R: fi, ctx: req.Context()}
|
||||
count, found, err := req.Option("count").Int()
|
||||
if err != nil {
|
||||
res.SetError(err, cmds.ErrNormal)
|
||||
@ -392,6 +392,19 @@ Examples:
|
||||
},
|
||||
}
|
||||
|
||||
type contextReader interface {
|
||||
CtxReadFull(context.Context, []byte) (int, error)
|
||||
}
|
||||
|
||||
type contextReaderWrapper struct {
|
||||
R contextReader
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
func (crw *contextReaderWrapper) Read(b []byte) (int, error) {
|
||||
return crw.R.CtxReadFull(crw.ctx, b)
|
||||
}
|
||||
|
||||
var FilesMvCmd = &cmds.Command{
|
||||
Helptext: cmds.HelpText{
|
||||
Tagline: "Move files.",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user