aboutsummaryrefslogtreecommitdiff
path: root/weed-fs/src/pkg
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2012-12-22 02:10:45 -0800
committerChris Lu <chris.lu@gmail.com>2012-12-22 02:10:45 -0800
commit9b95430e9f30498b94b483dd84fe3d166bf458d6 (patch)
tree684d6f978e33348f69c6b3137633fb7d488ddfc3 /weed-fs/src/pkg
parent37afb31d0515e7b5231cb370d7ac18e2e3956c1e (diff)
downloadseaweedfs-9b95430e9f30498b94b483dd84fe3d166bf458d6.tar.xz
seaweedfs-9b95430e9f30498b94b483dd84fe3d166bf458d6.zip
add store metadata:file name, mime type, is_gzipped
add support to upload .gz file directly
Diffstat (limited to 'weed-fs/src/pkg')
-rw-r--r--weed-fs/src/pkg/storage/compress.go3
-rw-r--r--weed-fs/src/pkg/storage/needle.go33
-rw-r--r--weed-fs/src/pkg/storage/needle_read_write.go7
3 files changed, 35 insertions, 8 deletions
diff --git a/weed-fs/src/pkg/storage/compress.go b/weed-fs/src/pkg/storage/compress.go
index 2de547869..419cde8ff 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.go
index aaea521a0..611e12882 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" //version2
Data []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 = data
n.Checksum = NewCRC(data)
diff --git a/weed-fs/src/pkg/storage/needle_read_write.go b/weed-fs/src/pkg/storage/needle_read_write.go
index fce67fc60..79eea8310 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
+}