From 0df55a731aa3330f82d22b010a7a2a4d66521972 Mon Sep 17 00:00:00 2001 From: Stefan Majewsky Date: Sun, 29 Apr 2018 21:19:14 +0200 Subject: initial support for large objects This has gone through a lot of iterations on my branch, and I'm quite happy with the parts of the API that exist now. Test coverage can still be better, and will get better in the following commits. The API is not yet finished: I want to add Options arguments to Object.Upload(), Object.Copy(), Object.Move() and Object.Delete() that specify how each of these operations affect existing segments (and, later, also existing symlinks). For Upload(), uploading in segments shall become as easy as flipping a single switch. --- object.go | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'object.go') diff --git a/object.go b/object.go index 8ef314a..4ff1f4f 100644 --- a/object.go +++ b/object.go @@ -167,15 +167,23 @@ func (o *Object) Update(headers ObjectHeaders, opts *RequestOptions) error { func (o *Object) Upload(content io.Reader, opts *RequestOptions) error { opts = cloneRequestOptions(opts, nil) hdr := ObjectHeaders{opts.Headers} - tryComputeContentLength(content, hdr) - tryComputeEtag(content, hdr) - //could not compute Etag in advance -> need to check on the fly + //do not attempt to add the Etag header when we're writing a large object + //manifest; the header refers to the content, but we would be computing the + //manifest's hash instead + isManifestUpload := opts.Values.Get("multipart-manifest") == "put" || hdr.IsDynamicLargeObject() + var hasher hash.Hash - if !hdr.Etag().Exists() { - hasher = md5.New() - if content != nil { - content = io.TeeReader(content, hasher) + tryComputeContentLength(content, hdr) + if !isManifestUpload { + tryComputeEtag(content, hdr) + + //could not compute Etag in advance -> need to check on the fly + if !hdr.Etag().Exists() { + hasher = md5.New() + if content != nil { + content = io.TeeReader(content, hasher) + } } } -- cgit v1.2.3