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
add store metadata:file name, mime type, is_gzipped add support to upload .gz file directly
Chris Lu9b95430e9f30
diff --git a/weed-fs/src/cmd/weed/volume.go b/weed-fs/src/cmd/weed/volume.goindex f12f9f4e07..4d3737dbd4 100644--- a/weed-fs/src/cmd/weed/volume.go+++ b/weed-fs/src/cmd/weed/volume.go@@ -129,10 +129,28 @@ func GetHandler(w http.ResponseWriter, r *http.Request) {w.WriteHeader(http.StatusNotFound)return}+ if n.NameSize > 0 {+ fname := string(n.Name)+ dotIndex := strings.LastIndex(fname, ".")+ if dotIndex > 0 {+ ext = fname[dotIndex:]+ }+ }+ mtype := ""if ext != "" {- mtype := mime.TypeByExtension(ext)+ mtype = mime.TypeByExtension(ext)+ }+ if n.MimeSize > 0 {+ mtype = string(n.Mime)+ }+ if mtype != "" {w.Header().Set("Content-Type", mtype)- if storage.IsGzippable(ext, mtype) {+ }+ if n.NameSize > 0 {+ w.Header().Set("Content-Disposition", "filename="+string(n.Name))+ }+ if ext != ".gz" {+ if n.IsGzipped() {if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") {w.Header().Set("Content-Encoding", "gzip")} else {@@ -140,6 +158,7 @@ func GetHandler(w http.ResponseWriter, r *http.Request) {}}}+ w.Header().Set("Content-Length", strconv.Itoa(len(n.Data)))w.Write(n.Data)}func PostHandler(w http.ResponseWriter, r *http.Request) {diff --git a/weed-fs/src/pkg/storage/compress.go b/weed-fs/src/pkg/storage/compress.goindex 2de5478690..419cde8fff 100644--- a/weed-fs/src/pkg/storage/compress.go+++ b/weed-fs/src/pkg/storage/compress.go@@ -15,6 +15,9 @@ func IsGzippable(ext, mtype string) bool {if ext == ".rar" {return false}+ if ext == ".gz" {+ return false+ }if strings.Index(mtype,"text/")==0 {return true}diff --git a/weed-fs/src/pkg/storage/needle.go b/weed-fs/src/pkg/storage/needle.goindex aaea521a08..611e12882e 100644--- a/weed-fs/src/pkg/storage/needle.go+++ b/weed-fs/src/pkg/storage/needle.go@@ -17,9 +17,9 @@ const ()type Needle struct {- Cookie uint32 "random number to mitigate brute force lookups"- Id uint64 "needle id"- Size uint32 "sum of DataSize,Data,NameSize,Name,MimeSize,Mime"+ Cookie uint32 "random number to mitigate brute force lookups"+ Id uint64 "needle id"+ Size uint32 "sum of DataSize,Data,NameSize,Name,MimeSize,Mime"DataSize uint32 "Data size" //version2Data []byte "The actual file data"@@ -50,15 +50,32 @@ func NewNeedle(r *http.Request) (n *Needle, fname string, e error) {}fname = part.FileName()data, _ := ioutil.ReadAll(part)- //log.Println("uploading file " + part.FileName())dotIndex := strings.LastIndex(fname, ".")+ ext, mtype := "", ""if dotIndex > 0 {- ext := fname[dotIndex:]- mtype := mime.TypeByExtension(ext)- if IsGzippable(ext, mtype) {- data = GzipData(data)+ ext = fname[dotIndex:]+ mtype = mime.TypeByExtension(ext)+ }+ contentType := part.Header.Get("Content-Type")+ if contentType != "" && mtype != contentType && len(contentType) < 256 {+ n.Mime = []byte(contentType)+ mtype = contentType+ }+ if IsGzippable(ext, mtype) {+ data = GzipData(data)+ n.SetGzipped()+ }+ if ext == ".gz" {+ n.SetGzipped()+ }+ if len(fname) < 256 {+ if strings.HasSuffix(fname, ".gz") {+ n.Name = []byte(fname[:len(fname)-3])+ } else {+ n.Name = []byte(fname)}}+n.Data = datan.Checksum = NewCRC(data)diff --git a/weed-fs/src/pkg/storage/needle_read_write.go b/weed-fs/src/pkg/storage/needle_read_write.goindex fce67fc605..79eea8310b 100644--- a/weed-fs/src/pkg/storage/needle_read_write.go+++ b/weed-fs/src/pkg/storage/needle_read_write.go@@ -142,3 +142,10 @@ func (n *Needle) ReadNeedleBody(r *os.File, version Version, bodyLength uint32)}return}++func (n *Needle) IsGzipped() bool{+ return n.Flags & 0x01 == 0x01+}+func (n *Needle) SetGzipped(){+ n.Flags = n.Flags | 0x01+}