Commit b078915f authored by Jeromy's avatar Jeromy

add context to files reading

License: MIT
Signed-off-by: default avatarJeromy <jeromyj@gmail.com>
parent b4a47e35
......@@ -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.",
......
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