mime

package module
v0.0.0-...-31ab248 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2016 License: EPL-1.0 Imports: 5 Imported by: 0

README

#+BEGIN_HTML
<img src="https://goreportcard.com/badge/github.com/lcaballero/mime" 
     tag="https://goreportcard.com/badge/github.com/lcaballero/mime" />

<a href="https://godoc.org/github.com/lcaballero/mime">
   <img src="https://godoc.org/github.com/lcaballero/mime?status.svg" alt="GoDoc"/>
</a>

<img src="https://travis-ci.org/lcaballero/mime.svg?branch=master"/>
#+END_HTML

* Overview

  This lib parses a file containing a loosely separated list of pairs.
  The pairs are those of mime-types to file extensions.

** Usage

*** Installation

#+BEGIN_SRC go
go get github.com/lcaballero/mime
#+END_SRC

*** Example Usage

After making a copy of mime-types.txt for your project and placing it
in a directory named `.file` the following code would parse the file
and make a map of extensions to mime-type.

#+BEGIN_SRC go
bin, _ := ioutil.ReadFile(".file/mime-types.txt")
r := bytes.NewReader(bin)

lookup, _ := mime.ParseExtensionsLookup(r)
mimeType, ok := lookup["jpeg"]

// mimeType == 'image/jpeg' typically at this point
#+END_SRC

** License

See License File.

The use and distribution terms for this software are covered by the
[[http://opensource.org/licenses/eclipse-1.0.txt][Eclipse Public License 1.0]], which can be found in the file ‘license’
at the root of this distribution. By using this software in any
fashion, you are agreeing to be bound by the terms of this
license. You must not remove this notice, or any other, from this
software.


Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExtensionToType

type ExtensionToType map[string]string

ExtensionToType maps the extension to its mime-type.

func LoadMimeTypes

func LoadMimeTypes(filename string) (ExtensionToType, error)

LoadMimeTypes reads the given file to produce a map of extensions to the mime-types appropriate for html content-type headers.

func ParseExtensionLookup

func ParseExtensionLookup(reader io.Reader) (ExtensionToType, error)

ParseExtensionLookup parses over the given reader producing an extension to mime-type lookup. An error is produced if the reader is nil or it find a malformed file.

type ToExtensions

type ToExtensions map[string][]string

ToExtensions is mapping from the mime-type to file extensions.

func Parse

func Parse(reader io.Reader) (ToExtensions, error)

Parse parses over the given reader producing a map of mime-types to file extensions for that type. An error is produced when the reader is nil or the file is malformed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL