MCPcopy Create free account
hub / github.com/google/go-cloud / WriteAll

Method WriteAll

blob/blob.go:1094–1112  ·  view source on GitHub ↗

WriteAll is a shortcut for creating a Writer via NewWriter and writing p. If opts.ContentMD5 is not set, WriteAll will compute the MD5 of p and use it as the ContentMD5 option for the Writer it creates. Using Upload may be more efficient.

(ctx context.Context, key string, p []byte, opts *WriterOptions)

Source from the content-addressed store, hash-verified

1092//
1093// Using Upload may be more efficient.
1094func (b *Bucket) WriteAll(ctx context.Context, key string, p []byte, opts *WriterOptions) (err error) {
1095 realOpts := new(WriterOptions)
1096 if opts != nil {
1097 *realOpts = *opts
1098 }
1099 if len(realOpts.ContentMD5) == 0 {
1100 sum := md5.Sum(p)
1101 realOpts.ContentMD5 = sum[:]
1102 }
1103 w, err := b.NewWriter(ctx, key, realOpts)
1104 if err != nil {
1105 return err
1106 }
1107 if _, err := w.Write(p); err != nil {
1108 _ = w.Close()
1109 return err
1110 }
1111 return w.Close()
1112}
1113
1114// Upload reads from an io.Reader r and writes into a blob.
1115//

Callers 15

TestErrorsAreWrappedFunction · 0.95
TestBucketIsClosedFunction · 0.95
TestPreconditionsFunction · 0.95
testListFunction · 0.95
testListWeirdKeysFunction · 0.95
testListDelimitersFunction · 0.95
testReadFunction · 0.95
testAttributesFunction · 0.95
testWriteFunction · 0.95
testCanceledWriteFunction · 0.95
testMetadataFunction · 0.95

Calls 3

NewWriterMethod · 0.95
WriteMethod · 0.95
CloseMethod · 0.95

Tested by 15

TestErrorsAreWrappedFunction · 0.76
TestBucketIsClosedFunction · 0.76
TestPreconditionsFunction · 0.76
TestListIterator_AllFunction · 0.64
TestWriteToFunction · 0.64
TestCopyBytesFunction · 0.64
TestPrefixedBucketFunction · 0.64
TestSingleKeyBucketFunction · 0.64
initBucketFunction · 0.64
TestOpenTelemetryFunction · 0.64
TestReaderFunction · 0.64
ExampleFunction · 0.64