diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 8c433d28f..de55309e1 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -24,8 +24,8 @@ }, { "ImportPath": "github.com/minio/minio-go", - "Comment": "v0.2.5-247-ge168a01", - "Rev": "e168a01f2683897cc623db67f39ccff35bec0597" + "Comment": "v0.2.5-251-ga4cd3ca", + "Rev": "a4cd3caabd5f9c35ac100110eb60c2b80798f1af" }, { "ImportPath": "github.com/pkg/sftp", diff --git a/Godeps/_workspace/src/github.com/minio/minio-go/.travis.yml b/Godeps/_workspace/src/github.com/minio/minio-go/.travis.yml index 2d2e8d841..32873865b 100644 --- a/Godeps/_workspace/src/github.com/minio/minio-go/.travis.yml +++ b/Godeps/_workspace/src/github.com/minio/minio-go/.travis.yml @@ -14,6 +14,7 @@ go: - 1.5.3 script: +- diff -au <(gofmt -d .) <(printf "") - go vet ./... - go test -short -race -v ./... diff --git a/Godeps/_workspace/src/github.com/minio/minio-go/api-put-object-common.go b/Godeps/_workspace/src/github.com/minio/minio-go/api-put-object-common.go index beab6d6cc..1584497bb 100644 --- a/Godeps/_workspace/src/github.com/minio/minio-go/api-put-object-common.go +++ b/Godeps/_workspace/src/github.com/minio/minio-go/api-put-object-common.go @@ -94,6 +94,58 @@ func optimalPartInfo(objectSize int64) (totalPartsCount int, partSize int64, las return totalPartsCount, partSize, lastPartSize, nil } +// Compatibility code for Golang < 1.5.x. +// copyBuffer is identical to io.CopyBuffer, since such a function is +// not available/implemented in Golang version < 1.5.x, we use a +// custom call exactly implementng io.CopyBuffer from Golang > 1.5.x +// version does. +// +// copyBuffer stages through the provided buffer (if one is required) +// rather than allocating a temporary one. If buf is nil, one is +// allocated; otherwise if it has zero length, copyBuffer panics. +// +// FIXME: Remove this code when distributions move to newer Golang versions. +func copyBuffer(writer io.Writer, reader io.Reader, buf []byte) (written int64, err error) { + // If the reader has a WriteTo method, use it to do the copy. + // Avoids an allocation and a copy. + if wt, ok := reader.(io.WriterTo); ok { + return wt.WriteTo(writer) + } + // Similarly, if the writer has a ReadFrom method, use it to do + // the copy. + if rt, ok := writer.(io.ReaderFrom); ok { + return rt.ReadFrom(reader) + } + if buf == nil { + buf = make([]byte, 32*1024) + } + for { + nr, er := reader.Read(buf) + if nr > 0 { + nw, ew := writer.Write(buf[0:nr]) + if nw > 0 { + written += int64(nw) + } + if ew != nil { + err = ew + break + } + if nr != nw { + err = io.ErrShortWrite + break + } + } + if er == io.EOF { + break + } + if er != nil { + err = er + break + } + } + return written, err +} + // hashCopyBuffer is identical to hashCopyN except that it stages // through the provided buffer (if one is required) rather than // allocating a temporary one. If buf is nil, one is allocated for 5MiB. @@ -113,9 +165,9 @@ func (c Client) hashCopyBuffer(writer io.Writer, reader io.Reader, buf []byte) ( buf = make([]byte, optimalReadBufferSize) } - // Using io.CopyBuffer to copy in large buffers, default buffer + // Using copyBuffer to copy in large buffers, default buffer // for io.Copy of 32KiB is too small. - size, err = io.CopyBuffer(hashWriter, reader, buf) + size, err = copyBuffer(hashWriter, reader, buf) if err != nil { return nil, nil, 0, err } @@ -215,7 +267,7 @@ func (c Client) computeHashBuffer(reader io.ReadSeeker, buf []byte) (md5Sum, sha return nil, nil, 0, err } } else { - size, err = io.CopyBuffer(hashWriter, reader, buf) + size, err = copyBuffer(hashWriter, reader, buf) if err != nil { return nil, nil, 0, err }