SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
refactoring
Chris Luee635dcc3600
diff --git a/weed/operation/upload_content.go b/weed/operation/upload_content.goindex 6806f7cf81..0fc3c37bf7 100644--- a/weed/operation/upload_content.go+++ b/weed/operation/upload_content.go@@ -2,7 +2,6 @@ package operationimport ("bytes"- "compress/flate""crypto/md5""encoding/json""errors"@@ -59,80 +58,23 @@ func UploadData(uploadUrl string, filename string, cipher bool, data []byte, isIfunc Upload(uploadUrl string, filename string, cipher bool, reader io.Reader, isInputGzipped bool, mtype string, pairMap map[string]string, jwt security.EncodedJwt) (uploadResult *UploadResult, err error) {hash := md5.New()reader = io.TeeReader(reader, hash)- uploadResult, err = doUpload(uploadUrl, filename, cipher, reader, isInputGzipped, mtype, pairMap, flate.BestSpeed, jwt)+ uploadResult, err = doUpload(uploadUrl, filename, cipher, reader, isInputGzipped, mtype, pairMap, jwt)if uploadResult != nil {uploadResult.Md5 = fmt.Sprintf("%x", hash.Sum(nil))}return}-func doUploadData(uploadUrl string, filename string, cipher bool, data []byte, isInputGzipped bool, mtype string, pairMap map[string]string, jwt security.EncodedJwt) (uploadResult *UploadResult, err error) {- contentIsGzipped := isInputGzipped- shouldGzipNow := false- if !isInputGzipped {- if shouldBeZipped, iAmSure := util.IsGzippableFileType(filepath.Base(filename), mtype); mtype == "" || iAmSure && shouldBeZipped {- shouldGzipNow = true- contentIsGzipped = true- }- }-- var clearDataLen int-- // gzip if possible- // this could be double copying- clearDataLen = len(data)- if shouldGzipNow {- data, err = util.GzipData(data)- } else if isInputGzipped {- // just to get the clear data length- clearData, err := util.UnGzipData(data)- if err == nil {- clearDataLen = len(clearData)- }- }-- if cipher {- // encrypt(gzip(data))-- // encrypt- cipherKey := util.GenCipherKey()- encryptedData, encryptionErr := util.Encrypt(data, cipherKey)- if encryptionErr != nil {- err = fmt.Errorf("encrypt input: %v", encryptionErr)- return- }-- // upload data- uploadResult, err = upload_content(uploadUrl, func(w io.Writer) (err error) {- _, err = w.Write(encryptedData)- return- }, "", false, "", nil, jwt)- if uploadResult != nil {- uploadResult.Name = filename- uploadResult.Mime = mtype- uploadResult.CipherKey = cipherKey- }- } else {- // upload data- uploadResult, err = upload_content(uploadUrl, func(w io.Writer) (err error) {- _, err = w.Write(data)- return- }, filename, contentIsGzipped, mtype, pairMap, jwt)- }-- if uploadResult == nil {+func doUpload(uploadUrl string, filename string, cipher bool, reader io.Reader, isInputGzipped bool, mtype string, pairMap map[string]string, jwt security.EncodedJwt) (uploadResult *UploadResult, err error) {+ data, readErr := ioutil.ReadAll(reader)+ if readErr != nil {+ err = fmt.Errorf("read input: %v", readErr)return}-- uploadResult.Size = uint32(clearDataLen)- if contentIsGzipped {- uploadResult.Gzip = 1- }-- return uploadResult, err+ return doUploadData(uploadUrl, filename, cipher, data, isInputGzipped, mtype, pairMap, jwt)}-func doUpload(uploadUrl string, filename string, cipher bool, reader io.Reader, isInputGzipped bool, mtype string, pairMap map[string]string, compression int, jwt security.EncodedJwt) (uploadResult *UploadResult, err error) {+func doUploadData(uploadUrl string, filename string, cipher bool, data []byte, isInputGzipped bool, mtype string, pairMap map[string]string, jwt security.EncodedJwt) (uploadResult *UploadResult, err error) {contentIsGzipped := isInputGzippedshouldGzipNow := falseif !isInputGzipped {@@ -146,11 +88,6 @@ func doUpload(uploadUrl string, filename string, cipher bool, reader io.Reader,// gzip if possible// this could be double copying- data, readErr := ioutil.ReadAll(reader)- if readErr != nil {- err = fmt.Errorf("read input: %v", readErr)- return- }clearDataLen = len(data)if shouldGzipNow {data, err = util.GzipData(data)@@ -182,7 +119,6 @@ func doUpload(uploadUrl string, filename string, cipher bool, reader io.Reader,uploadResult.Name = filenameuploadResult.Mime = mtypeuploadResult.CipherKey = cipherKey- uploadResult.Size = uint32(clearDataLen)}} else {// upload data