]> Cypherpunks repositories - gostls13.git/commitdiff
mime: add support for Plan 9
authorAnthony Martin <ality@pbrane.org>
Wed, 5 Jun 2013 00:30:45 +0000 (17:30 -0700)
committerAnthony Martin <ality@pbrane.org>
Wed, 5 Jun 2013 00:30:45 +0000 (17:30 -0700)
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/10028043

src/pkg/mime/testdata/test.types.plan9 [new file with mode: 0644]
src/pkg/mime/type_plan9.go [new file with mode: 0644]
src/pkg/mime/type_unix.go

diff --git a/src/pkg/mime/testdata/test.types.plan9 b/src/pkg/mime/testdata/test.types.plan9
new file mode 100644 (file)
index 0000000..19dbf41
--- /dev/null
@@ -0,0 +1,8 @@
+# Copyright 2013 The Go Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style
+# license that can be found in the LICENSE file.
+
+
+ # mime package test
+.t1            application     test            -               y # Simple test 
+.t2            text            test            -               y # Text test   
diff --git a/src/pkg/mime/type_plan9.go b/src/pkg/mime/type_plan9.go
new file mode 100644 (file)
index 0000000..b8f0511
--- /dev/null
@@ -0,0 +1,53 @@
+// Copyright 2013 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package mime
+
+import (
+       "bufio"
+       "os"
+       "strings"
+)
+
+var typeFiles = []string{
+       "/sys/lib/mimetypes",
+}
+
+func loadMimeFile(filename string) {
+       f, err := os.Open(filename)
+       if err != nil {
+               return
+       }
+       defer f.Close()
+
+       scanner := bufio.NewScanner(f)
+       for scanner.Scan() {
+               fields := strings.Fields(scanner.Text())
+               if len(fields) <= 2 || fields[0][0] != '.' {
+                       continue
+               }
+               if fields[1] == "-" || fields[2] == "-" {
+                       continue
+               }
+               setExtensionType(fields[0], fields[1]+"/"+fields[2])
+       }
+       if err := scanner.Err(); err != nil {
+               panic(err)
+       }
+}
+
+func initMime() {
+       for _, filename := range typeFiles {
+               loadMimeFile(filename)
+       }
+}
+
+func initMimeForTests() map[string]string {
+       typeFiles = []string{"testdata/test.types.plan9"}
+       return map[string]string{
+               ".t1":  "application/test",
+               ".t2":  "text/test; charset=utf-8",
+               ".png": "image/png",
+       }
+}
index 857a0ab6765d83114ef2f02bb64ad4c1cd557711..e0050bb958958d9200e910a455ef96a55d34d5a7 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd plan9
+// +build darwin freebsd linux netbsd openbsd
 
 package mime