Add code comment

Adding a code comment that explains setting MD5 Sum field.

Signed-off-by: Milos Gajdos <milosthegajdos@gmail.com>
This commit is contained in:
Milos Gajdos
2025-03-01 07:35:41 -08:00
parent e20645c050
commit 7884c71297

View File

@@ -426,6 +426,10 @@ func (d *driver) putContent(ctx context.Context, obj *storage.ObjectHandle, cont
if _, err := bytes.NewReader(content).WriteTo(wc); err != nil {
return err
}
// NOTE(milosgajdos): Apparently it's posisble to to upload 0-byte content to GCS.
// Setting MD5 on the Writer helps to prevent presisting that data.
// If set, the uploaded data is rejected if its MD5 hash does not match this field.
// See: https://pkg.go.dev/cloud.google.com/go/storage#ObjectAttrs
h := md5.New()
h.Write(content)
wc.MD5 = h.Sum(nil)