]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blob - vendor/github.com/hashicorp/go-getter/get_file_copy.go
Upgrade to 0.12
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / go-getter / get_file_copy.go
1 package getter
2
3 import (
4 "context"
5 "io"
6 )
7
8 // readerFunc is syntactic sugar for read interface.
9 type readerFunc func(p []byte) (n int, err error)
10
11 func (rf readerFunc) Read(p []byte) (n int, err error) { return rf(p) }
12
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) {
18
19 select {
20 case <-ctx.Done():
21 // context has been canceled
22 // stop process and propagate "context canceled" error
23 return 0, ctx.Err()
24 default:
25 // otherwise just run default io.Reader implementation
26 return src.Read(p)
27 }
28 }))
29 }