Data.MIME.Types

MissingH-1.4.0.1: Large utility library

Copyright | Copyright (C) 2004-2011 John Goerzen
License | BSD3
Maintainer | John Goerzen <jgoerzen@complete.org>
Stability | provisional
Portability | portable
Safe Haskell | None
Language | Haskell98

Data.MIME.Types

Contents

- Creating Lookup Objects
- Basic Access

Description

Utilities for guessing MIME types of files.

Written by John Goerzen, jgoerzen@complete.org

Synopsis

- defaultmtd :: MIMETypeData
- readMIMETypes :: MIMETypeData -> Bool -> FilePath -> IO MIMETypeData
- hReadMIMETypes :: MIMETypeData -> Bool -> Handle -> IO MIMETypeData
- readSystemMIMETypes :: MIMETypeData -> IO MIMETypeData
- type MIMEResults = (Maybe String, Maybe String)
- data MIMETypeData = MIMETypeData {
  - suffixMap :: Map String String
  - encodingsMap :: Map String String
  - typesMap :: Map String String
  - commonTypesMap :: Map String String
  }
- guessType :: MIMETypeData -> Bool -> String -> MIMEResults
- guessExtension :: MIMETypeData -> Bool -> String -> Maybe String
- guessAllExtensions :: MIMETypeData -> Bool -> String -> [String]

# Creating Lookup Objects

defaultmtd :: MIMETypeData

Default MIME type data to use

readMIMETypes

Arguments

:: MIMETypeData | Data to work with
-> Bool | Whether to work on strict data
-> FilePath | File to read
-> IO MIMETypeData | New object

Read the given mime.types file and add it to an existing object. Returns new object.

hReadMIMETypes

Arguments

:: MIMETypeData | Data to work with
-> Bool | Whether to work on strict data
-> Handle | Handle to read from
-> IO MIMETypeData | New object

Load a mime.types file from an already-open handle.

readSystemMIMETypes :: MIMETypeData -> IO MIMETypeData

Read the system's default mime.types files, and add the data contained therein to the passed object, then return the new one.

# Basic Access

type MIMEResults = (Maybe String, Maybe String)

Return value from guessing a file's type.

The first element of the tuple gives the MIME type. It is Nothing if no suitable type could be found.

The second element gives the encoding. It is Nothing if there was no particular encoding for the file, or if no encoding could be found.

data MIMETypeData

Constructors

MIMETypeData |
Fields suffixMap :: Map String String A mapping used to expand common suffixes into equivolent, better-parsed versions. For instance, ".tgz" would expand into ".tar.gz". encodingsMap :: Map String String A mapping used to determine the encoding of a file. This is used, for instance, to map ".gz" to "gzip". typesMap :: Map String String A mapping used to map extensions to MIME types. commonTypesMap :: Map String String A mapping used to augment the `typesMap` when non-strict lookups are used.

guessType

Arguments

:: MIMETypeData | Source data for guessing
-> Bool | Whether to limit to strict data
-> String | File or URL name to consider
-> MIMEResults | Result of guessing (see `MIMEResults` for details on interpreting it)

Guess the type of a file given a filename or URL. The file is not opened; only the name is considered.

guessExtension

Arguments

:: MIMETypeData | Source data for guessing
-> Bool | Whether to limit to strict data
-> String | MIME type to consider
-> Maybe String | Result of guessing, or Nothing if no match possible

Guess the extension of a file based on its MIME type. The return value includes the leading dot.

Returns Nothing if no extension could be found.

In the event that multiple possible extensions are available, one of them will be picked and returned. The logic to select one of these should be considered undefined.

guessAllExtensions

Arguments

:: MIMETypeData | Source data for guessing
-> Bool | Whether to limit to strict data
-> String | MIME type to consider
-> [String] | Result of guessing

Similar to `guessExtension`, but returns a list of all possible matching extensions, or the empty list if there are no matches.