diff options
Diffstat (limited to 'vendor/cloud.google.com/go/storage/writer.go')
-rw-r--r-- | vendor/cloud.google.com/go/storage/writer.go | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/vendor/cloud.google.com/go/storage/writer.go b/vendor/cloud.google.com/go/storage/writer.go index 79ab791..8f98156 100644 --- a/vendor/cloud.google.com/go/storage/writer.go +++ b/vendor/cloud.google.com/go/storage/writer.go @@ -15,6 +15,7 @@ package storage import ( + "errors" "fmt" "io" "unicode/utf8" @@ -31,6 +32,17 @@ type Writer struct { // attributes are ignored. ObjectAttrs + // ChunkSize controls the maximum number of bytes of the object that the + // Writer will attempt to send to the server in a single request. Objects + // smaller than the size will be sent in a single request, while larger + // objects will be split over multiple requests. The size will be rounded up + // to the nearest multiple of 256K. If zero, chunking will be disabled and + // the object will be uploaded in a single request. + // + // ChunkSize will default to a reasonable value. Any custom configuration + // must be done before the first Write call. + ChunkSize int + ctx context.Context o *ObjectHandle @@ -56,7 +68,12 @@ func (w *Writer) open() error { w.pw = pw w.opened = true - var mediaOpts []googleapi.MediaOption + if w.ChunkSize < 0 { + return errors.New("storage: Writer.ChunkSize must non-negative") + } + mediaOpts := []googleapi.MediaOption{ + googleapi.ChunkSize(w.ChunkSize), + } if c := attrs.ContentType; c != "" { mediaOpts = append(mediaOpts, googleapi.ContentType(c)) } @@ -70,9 +87,9 @@ func (w *Writer) open() error { Context(w.ctx) var resp *raw.Object - err := applyConds("NewWriter", w.o.conds, call) + err := applyConds("NewWriter", w.o.gen, w.o.conds, call) if err == nil { - resp, err = call.Do() + err = runWithRetry(w.ctx, func() error { resp, err = call.Do(); return err }) } if err != nil { w.err = err |