Media (AKA MIME) types
There's often a need to know content types.
Email can contain other documents of varying types. The Web can serve files of any kind. Email extensions evolved into "Media Types".
To use bindings from this module
(import :std/mime/types)
path-extension->mime-type-name
(path-extension->mime-type-name path) => string or #f
path := a filename
The define-mime-types
database has a mime-extensions
map the get a mime-type
from an extension via extension->mime-type
. This procedure unites them.
> (path-extension->mime-type-name "foo.ss")
"text/x-scheme.gerbil"
> (path-extension->mime-type-name "around-the-world.mp3")
"audio/mpeg"
> (path-extension->mime-type-name "Urgent: Outlook mail!.msg")
"application/vnd.ms-outlook"
extension->mime-type
(extension->mime-type str) => mime-type or #f
mime-extensions
(def mime-extensions (make-hash-table))
A map of extensions to mime-type
's.
mime-types
(def mime-types (make-hash-table))
A map of names to mime-types
add-mime-type
(add-mime-type name ext ...) => mime-type
Add a newly created mime=type
to the mime-types
and mime-extensions
mapping.
make-mime-type
(make-mime-type name ext ...) => mime-type
mime-type
(defstruct mime-type (name extensions) transparent: #t constructor: :init!)
define-mime-types
(define-mime-types
file-or-definition ...)
file := A path tp a file like `/etc/mime.types`
definition := ("type/name" "ext" ...)
(define-mime-types
"./mime.types"
("text/x-scheme" "scm" "sps" "sls" "sld")
("text/x-scheme.gerbil" "ss")
("application/vnd.ms-outlook" "msg"))