Commit 5567592c authored by Anthony Martin's avatar Anthony Martin

mime: add support for Plan 9

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/10028043
parent 427bec62
# 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
// 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",
}
}
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment