storage: allow set accept-encoding for object request
Fixes
@@ -266,6 +266,7 @@ type ObjectHandle struct {
conds *Conditions
encryptionKey []byte // AES-256 key
userProject string // for requester-pays buckets
+ readCompressed bool // Accept-Encoding: gzip
}
// ACL provides access to the object's access control list.
@@ -467,6 +468,13 @@ func (o *ObjectHandle) Delete(ctx context.Context) error {
return err
}
+// ReadCompressed when true causes the read to happen without decompressing.
+func (o *ObjectHandle) ReadCompressed(compressed bool) *ObjectHandle {
+ o2 := *o
+ o2.readCompressed = compressed
+ return &o2
+}
+
// NewReader creates a new Reader to read the contents of the
// object.
// ErrObjectNotExist will be returned if the object is not found.
@@ -514,6 +522,9 @@ func (o *ObjectHandle) NewRangeReader(ctx context.Context, offset, length int64)
if o.userProject != "" {
req.Header.Set("X-Goog-User-Project", o.userProject)
}
+ if o.readCompressed {
+ req.Header.Set("Accept-Encoding", "gzip")
+ }
if err := setEncryptionHeaders(req.Header, o.encryptionKey, false); err != nil {
return nil, err
}
