Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exported mimetypes (#127) #258

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions mimetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func Detect(in []byte) *MIME {
}
mu.RLock()
defer mu.RUnlock()
return root.match(in, l)
return OctetStream.match(in, l)
}

// DetectReader returns the MIME type of the provided reader.
Expand Down Expand Up @@ -65,7 +65,7 @@ func DetectReader(r io.Reader) (*MIME, error) {

mu.RLock()
defer mu.RUnlock()
return root.match(in, l), nil
return OctetStream.match(in, l), nil
}

// DetectFile returns the MIME type of the provided file.
Expand Down Expand Up @@ -111,13 +111,13 @@ func SetLimit(limit uint32) {
// Extend adds detection for other file formats.
// It is equivalent to calling Extend() on the root mime type "application/octet-stream".
func Extend(detector func(raw []byte, limit uint32) bool, mime, extension string, aliases ...string) {
root.Extend(detector, mime, extension, aliases...)
OctetStream.Extend(detector, mime, extension, aliases...)
}

// Lookup finds a MIME object by its string representation.
// The representation can be the main mime type, or any of its aliases.
func Lookup(mime string) *MIME {
mu.RLock()
defer mu.RUnlock()
return root.lookup(mime)
return OctetStream.lookup(mime)
}
20 changes: 10 additions & 10 deletions mimetype_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ func TestGenerateSupportedFormats(t *testing.T) {
}
defer f.Close()

nodes := root.flatten()
nodes := OctetStream.flatten()
header := fmt.Sprintf(`## %d Supported MIME types
This file is automatically generated when running tests. Do not edit manually.

Expand Down Expand Up @@ -517,7 +517,7 @@ func BenchmarkCommon(b *testing.B) {

// Check there are no panics for nil inputs.
func TestIndexOutOfRangePanic(t *testing.T) {
for _, n := range root.flatten() {
for _, n := range OctetStream.flatten() {
n.detector(nil, 1<<10)
}
}
Expand All @@ -526,7 +526,7 @@ func TestIndexOutOfRangePanic(t *testing.T) {
// parse each alias when testing for equality, we must ensure they are
// registered with no parameters.
func TestMIMEFormat(t *testing.T) {
for _, n := range root.flatten() {
for _, n := range OctetStream.flatten() {
// All extensions must be dot prefixed so they are compatible
// with the stdlib mime package.
if n.Extension() != "" && !strings.HasPrefix(n.Extension(), ".") {
Expand Down Expand Up @@ -555,10 +555,10 @@ func TestLookup(t *testing.T) {
mime string
m *MIME
}{
{root.mime, root},
{zip.mime, zip},
{zip.aliases[0], zip},
{xlsx.mime, xlsx},
{OctetStream.mime, OctetStream},
{Zip.mime, Zip},
{Zip.aliases[0], Zip},
{Xlsx.mime, Xlsx},
}

for _, tt := range data {
Expand All @@ -577,8 +577,8 @@ func TestExtend(t *testing.T) {
parent *MIME
}{
{"foo", ".foo", nil},
{"bar", ".bar", root},
{"baz", ".baz", zip},
{"bar", ".bar", OctetStream},
{"baz", ".baz", Zip},
}

for _, tt := range data {
Expand All @@ -587,7 +587,7 @@ func TestExtend(t *testing.T) {
if tt.parent != nil {
extend = tt.parent.Extend
} else {
tt.parent = root
tt.parent = OctetStream
}

extend(func(raw []byte, limit uint32) bool { return false }, tt.mime, tt.ext)
Expand Down
Loading