8 // readerFunc is syntactic sugar for read interface.
9 type readerFunc func(p []byte) (n int, err error)
11 func (rf readerFunc) Read(p []byte) (n int, err error) { return rf(p) }
13 // Copy is a io.Copy cancellable by context
14 func Copy(ctx context.Context, dst io.Writer, src io.Reader) (int64, error) {
15 // Copy will call the Reader and Writer interface multiple time, in order
16 // to copy by chunk (avoiding loading the whole file in memory).
17 return io.Copy(dst, readerFunc(func(p []byte) (int, error) {
21 // context has been canceled
22 // stop process and propagate "context canceled" error
25 // otherwise just run default io.Reader implementation