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

mime: should be able to determine an appropriate extension for a given MIME type #10144

Closed
ghost opened this issue Mar 12, 2015 · 1 comment
Closed
Milestone

Comments

@ghost
Copy link

ghost commented Mar 12, 2015

Currently it is possible to go from a file extension to a MIME type using TypeForExtension, but the converse is missing. This is useful in applications where it is saving or producing new content of variable type, and needs to know the expected extension.

Proposed API:
func ExtensionsForType(typ string) ([]string, error)

This is the symmetric partner of TypeForExtension, it determines the file extensions for the given type (formatted per RFC 1521, so accepted by ParseMediaType). It does not consider any optional parameters.

The error return value is used solely where the provided MIME type does not parse, distinct from 'no extensions registered', which is an empty slice.

@mikioh mikioh added this to the Go1.5 milestone Mar 27, 2015
@deiu
Copy link

deiu commented Jul 13, 2015

Testing ExtensionByType() with mime text/html under OS X 10.10.4. running go1.5beta1 darwin/amd64 produces inconsistent results. I noticed that in about 1/10 cases it returns .html instead of .htm.

@golang golang locked and limited conversation to collaborators Jul 13, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants