diff options
| author | Chris Lu <chris.lu@gmail.com> | 2019-04-18 20:21:28 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2019-04-18 20:21:28 -0700 |
| commit | a2d34d4802978b294d536966aa98bec34058eea9 (patch) | |
| tree | c525510fe5064cbea0a89c58e867f612ba5fc226 /weed/operation | |
| parent | 072644969e276d6071bed13cbf95320d25b8d468 (diff) | |
| download | seaweedfs-a2d34d4802978b294d536966aa98bec34058eea9.tar.xz seaweedfs-a2d34d4802978b294d536966aa98bec34058eea9.zip | |
filer.copy: add adjustable compression level
Diffstat (limited to 'weed/operation')
| -rw-r--r-- | weed/operation/upload_content.go | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/weed/operation/upload_content.go b/weed/operation/upload_content.go index dcab1a0ae..4417a0e70 100644 --- a/weed/operation/upload_content.go +++ b/weed/operation/upload_content.go @@ -39,8 +39,23 @@ func init() { var fileNameEscaper = strings.NewReplacer("\\", "\\\\", "\"", "\\\"") -// Upload sends a POST request to a volume server to upload the content +// Upload sends a POST request to a volume server to upload the content with adjustable compression level +func UploadWithLocalCompressionLevel(uploadUrl string, filename string, reader io.Reader, isGzipped bool, mtype string, pairMap map[string]string, jwt security.EncodedJwt, compressionLevel int) (*UploadResult, error) { + if compressionLevel < 1 { + compressionLevel = 1 + } + if compressionLevel > 9 { + compressionLevel = 9 + } + return doUpload(uploadUrl, filename, reader, isGzipped, mtype, pairMap, compressionLevel, jwt) +} + +// Upload sends a POST request to a volume server to upload the content with fast compression func Upload(uploadUrl string, filename string, reader io.Reader, isGzipped bool, mtype string, pairMap map[string]string, jwt security.EncodedJwt) (*UploadResult, error) { + return doUpload(uploadUrl, filename, reader, isGzipped, mtype, pairMap, flate.BestSpeed, jwt) +} + +func doUpload(uploadUrl string, filename string, reader io.Reader, isGzipped bool, mtype string, pairMap map[string]string, compression int, jwt security.EncodedJwt) (*UploadResult, error) { contentIsGzipped := isGzipped shouldGzipNow := false if !isGzipped { @@ -51,7 +66,7 @@ func Upload(uploadUrl string, filename string, reader io.Reader, isGzipped bool, } return upload_content(uploadUrl, func(w io.Writer) (err error) { if shouldGzipNow { - gzWriter, _ := gzip.NewWriterLevel(w, flate.BestSpeed) + gzWriter, _ := gzip.NewWriterLevel(w, compression) _, err = io.Copy(gzWriter, reader) gzWriter.Close() } else { @@ -60,6 +75,7 @@ func Upload(uploadUrl string, filename string, reader io.Reader, isGzipped bool, return }, filename, contentIsGzipped, mtype, pairMap, jwt) } + func upload_content(uploadUrl string, fillBufferFunction func(w io.Writer) error, filename string, isGzipped bool, mtype string, pairMap map[string]string, jwt security.EncodedJwt) (*UploadResult, error) { body_buf := bytes.NewBufferString("") body_writer := multipart.NewWriter(body_buf) |
