Skip to content

Commit

Permalink
add context to files reading
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Jeromy <jeromyj@gmail.com>
  • Loading branch information
whyrusleeping committed Jan 12, 2016
1 parent afcf8ca commit 39db30c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion core/commands/files/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,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)
Expand All @@ -379,6 +379,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",
Expand Down

0 comments on commit 39db30c

Please sign in to comment.