Skip to content

Commit 847206c

Browse files
committed
feat: add checksums for single chunk json uploads
1 parent 8e75a1d commit 847206c

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

google-api-go-generator/gen.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2280,6 +2280,13 @@ func (meth *Method) generateCode() {
22802280
} else {
22812281
pn(`reqHeaders := gensupport.SetHeaders(c.s.userAgent(), %s, c.header_, "x-goog-api-version", %q)`, contentType, apiVersion)
22822282
}
2283+
if meth.supportsMediaUpload() && meth.api.Name == "storage" {
2284+
comment = "Set auto checksum in case of a single chunk upload if enabled."
2285+
p("%s", asComment("", comment))
2286+
pn("if c.mediaInfo_ != nil {")
2287+
pn(" c.object.Crc32c = c.mediaInfo_.GetAutoChecksum()")
2288+
pn("}")
2289+
}
22832290
if httpMethod == "GET" {
22842291
pn(`if c.ifNoneMatch_ != "" {`)
22852292
pn(` reqHeaders.Set("If-None-Match", c.ifNoneMatch_)`)

internal/gensupport/media.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,15 @@ func (mi *MediaInfo) UploadType() string {
198198
return "resumable"
199199
}
200200

201+
func (mi *MediaInfo) GetAutoChecksum() string {
202+
if mi.buffer.enableAutoChecksum &&
203+
mi.buffer != nil &&
204+
mi.singleChunk {
205+
return encodeUint32(mi.buffer.fullObjectChecksum + 1)
206+
}
207+
return ""
208+
}
209+
201210
// UploadRequest sets up an HTTP request for media upload. It adds headers
202211
// as necessary, and returns a replacement for the body and a function for http.Request.GetBody.
203212
func (mi *MediaInfo) UploadRequest(reqHeaders http.Header, body io.Reader) (newBody io.Reader, getBody func() (io.ReadCloser, error), cleanup func()) {

storage/v1/storage-gen.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)