Copyright 2014 Google LLC Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
ObjectAttrs are optional attributes to set on the object. Any attributes must be initialized before the first Write call. Nil or zero-valued attributes are ignored.
SendCRC specifies whether to transmit a CRC32C field. It should be set to true in addition to setting the Writer's CRC32C field, because zero is a valid CRC and normally a zero would not be transmitted. If a CRC32C is sent, and the data written does not match the checksum, the write will be rejected.
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. ChunkSize will default to a reasonable value. If you perform many concurrent writes of small objects (under ~8MB), you may wish set ChunkSize to a value that matches your objects' sizes to avoid consuming large amounts of memory. See https://cloud.google.com/storage/docs/json_api/v1/how-tos/upload#size for more information about performance trade-offs related to ChunkSize. If ChunkSize is set to zero, chunking will be disabled and the object will be uploaded in a single request without the use of a buffer. This will further reduce memory used during uploads, but will also prevent the writer from retrying in case of a transient error from the server, since a buffer is required in order to retry the failed request. ChunkSize must be set before the first Write call.
ProgressFunc can be used to monitor the progress of a large write. operation. If ProgressFunc is not nil and writing requires multiple calls to the underlying service (see https://cloud.google.com/storage/docs/json_api/v1/how-tos/resumable-upload), then ProgressFunc will be invoked after each call with the number of bytes of content copied so far. ProgressFunc should return quickly without blocking.
The internals that perform call.Do automatically retry both the initial call to set up the upload as well as calls to upload individual chunks for a resumable upload (as long as the chunk size is non-zero). Hence there is no need to add retries here.
Write appends to w. It implements the io.Writer interface. Since writes happen asynchronously, Write may return a nil error even though the write failed (or will fail). Always use the error returned from Writer.Close to determine if the upload was successful. Writes will be retried on transient errors from the server, unless Writer.ChunkSize has been set to zero.
Preserve existing functionality that when context is canceled, Write will return context.Canceled instead of "io: read/write on closed pipe". This hides the pipe implementation detail from users and makes Write seem as though it's an RPC.
Close completes the write operation and flushes any buffered data. If Close doesn't return an error, metadata about the written object can be retrieved by calling Attrs.
monitorCancel is intended to be used as a background goroutine. It monitors the context, and when it observes that the context has been canceled, it manually closes things that do not take a context.
CloseWithError aborts the write operation with the provided error. CloseWithError always returns nil. Deprecated: cancel the context passed to NewWriter instead.
The pages are generated with Goldsv0.3.2-preview. (GOOS=darwin GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.