@ -33,7 +33,6 @@ import (
"time"
"time"
snappy "github.com/golang/snappy"
"github.com/gorilla/mux"
"github.com/gorilla/mux"
miniogo "github.com/minio/minio-go"
miniogo "github.com/minio/minio-go"
"github.com/minio/minio-go/pkg/encrypt"
"github.com/minio/minio-go/pkg/encrypt"
@ -831,21 +830,9 @@ func (api objectAPIHandlers) CopyObjectHandler(w http.ResponseWriter, r *http.Re
// Remove all source encrypted related metadata to
// Remove all source encrypted related metadata to
// avoid copying them in target object.
// avoid copying them in target object.
crypto . RemoveInternalEntries ( srcInfo . UserDefined )
crypto . RemoveInternalEntries ( srcInfo . UserDefined )
// Open a pipe for compression.
// Where pipeWriter is piped to srcInfo.Reader.
// gr writes to pipeWriter.
pipeReader , pipeWriter := io . Pipe ( )
reader = pipeReader
length = - 1
snappyWriter := snappy . NewBufferedWriter ( pipeWriter )
go func ( ) {
reader = newSnappyCompressReader ( gr )
// Compress the decompressed source object.
length = - 1
_ , cerr := io . Copy ( snappyWriter , gr )
snappyWriter . Close ( )
pipeWriter . CloseWithError ( cerr )
} ( )
} else {
} else {
// Remove the metadata for remote calls.
// Remove the metadata for remote calls.
delete ( srcInfo . UserDefined , ReservedMetadataPrefix + "compression" )
delete ( srcInfo . UserDefined , ReservedMetadataPrefix + "compression" )
@ -1216,28 +1203,17 @@ func (api objectAPIHandlers) PutObjectHandler(w http.ResponseWriter, r *http.Req
metadata [ ReservedMetadataPrefix + "compression" ] = compressionAlgorithmV1
metadata [ ReservedMetadataPrefix + "compression" ] = compressionAlgorithmV1
metadata [ ReservedMetadataPrefix + "actual-size" ] = strconv . FormatInt ( size , 10 )
metadata [ ReservedMetadataPrefix + "actual-size" ] = strconv . FormatInt ( size , 10 )
pipeReader , pipeWriter := io . Pipe ( )
actualReader , err := hash . NewReader ( reader , size , md5hex , sha256hex , actualSize )
snappyWriter := snappy . NewBufferedWriter ( pipeWriter )
var actualReader * hash . Reader
actualReader , err = hash . NewReader ( reader , size , md5hex , sha256hex , actualSize )
if err != nil {
if err != nil {
writeErrorResponse ( ctx , w , toAPIError ( ctx , err ) , r . URL , guessIsBrowserReq ( r ) )
writeErrorResponse ( ctx , w , toAPIError ( ctx , err ) , r . URL , guessIsBrowserReq ( r ) )
return
return
}
}
go func ( ) {
// Writing to the compressed writer.
_ , cerr := io . CopyN ( snappyWriter , actualReader , actualSize )
snappyWriter . Close ( )
pipeWriter . CloseWithError ( cerr )
} ( )
// Set compression metrics.
// Set compression metrics.
reader = newSnappyCompressReader ( actualReader )
size = - 1 // Since compressed size is un-predictable.
size = - 1 // Since compressed size is un-predictable.
md5hex = "" // Do not try to verify the content.
md5hex = "" // Do not try to verify the content.
sha256hex = ""
sha256hex = ""
reader = pipeReader
}
}
hashReader , err := hash . NewReader ( reader , size , md5hex , sha256hex , actualSize )
hashReader , err := hash . NewReader ( reader , size , md5hex , sha256hex , actualSize )
@ -1654,21 +1630,8 @@ func (api objectAPIHandlers) CopyObjectPartHandler(w http.ResponseWriter, r *htt
isCompressed := compressPart
isCompressed := compressPart
// Compress only if the compression is enabled during initial multipart.
// Compress only if the compression is enabled during initial multipart.
if isCompressed {
if isCompressed {
// Open a pipe for compression.
reader = newSnappyCompressReader ( gr )
// Where pipeWriter is piped to srcInfo.Reader.
// gr writes to pipeWriter.
pipeReader , pipeWriter := io . Pipe ( )
reader = pipeReader
length = - 1
length = - 1
snappyWriter := snappy . NewBufferedWriter ( pipeWriter )
go func ( ) {
// Compress the decompressed source object.
_ , cerr := io . Copy ( snappyWriter , gr )
snappyWriter . Close ( )
pipeWriter . CloseWithError ( cerr )
} ( )
} else {
} else {
reader = gr
reader = gr
}
}
@ -1879,8 +1842,6 @@ func (api objectAPIHandlers) PutObjectPartHandler(w http.ResponseWriter, r *http
}
}
actualSize := size
actualSize := size
var pipeReader * io . PipeReader
var pipeWriter * io . PipeWriter
// get encryption options
// get encryption options
var opts ObjectOptions
var opts ObjectOptions
@ -1902,28 +1863,17 @@ func (api objectAPIHandlers) PutObjectPartHandler(w http.ResponseWriter, r *http
isCompressed := false
isCompressed := false
if objectAPI . IsCompressionSupported ( ) && compressPart {
if objectAPI . IsCompressionSupported ( ) && compressPart {
pipeReader , pipeWriter = io . Pipe ( )
actualReader , err := hash . NewReader ( reader , size , md5hex , sha256hex , actualSize )
snappyWriter := snappy . NewBufferedWriter ( pipeWriter )
var actualReader * hash . Reader
actualReader , err = hash . NewReader ( reader , size , md5hex , sha256hex , actualSize )
if err != nil {
if err != nil {
writeErrorResponse ( ctx , w , toAPIError ( ctx , err ) , r . URL , guessIsBrowserReq ( r ) )
writeErrorResponse ( ctx , w , toAPIError ( ctx , err ) , r . URL , guessIsBrowserReq ( r ) )
return
return
}
}
go func ( ) {
// Writing to the compressed writer.
_ , cerr := io . CopyN ( snappyWriter , actualReader , actualSize )
snappyWriter . Close ( )
pipeWriter . CloseWithError ( cerr )
} ( )
// Set compression metrics.
// Set compression metrics.
reader = newSnappyCompressReader ( actualReader )
size = - 1 // Since compressed size is un-predictable.
size = - 1 // Since compressed size is un-predictable.
md5hex = "" // Do not try to verify the content.
md5hex = "" // Do not try to verify the content.
sha256hex = ""
sha256hex = ""
reader = pipeReader
isCompressed = true
isCompressed = true
}
}
@ -2016,7 +1966,6 @@ func (api objectAPIHandlers) PutObjectPartHandler(w http.ResponseWriter, r *http
etag := partInfo . ETag
etag := partInfo . ETag
if isCompressed {
if isCompressed {
pipeWriter . Close ( )
// Suppress compressed ETag.
// Suppress compressed ETag.
etag = partInfo . ETag + "-1"
etag = partInfo . ETag + "-1"
} else if isEncrypted {
} else if isEncrypted {