]> gitweb.factorcode.org Git - factor.git/blob - basis/mime/types/types.factor
81518d53197bd4cef9e3bb407032798f03d977ea
[factor.git] / basis / mime / types / types.factor
1 ! Copyright (C) 2004, 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: io.pathnames io.files io.encodings.ascii
4 io.encodings.binary io.encodings.utf8 assocs sequences
5 splitting kernel make fry memoize ;
6 IN: mime.types
7
8 MEMO: mime-db ( -- seq )
9     "vocab:mime/types/mime.types" ascii file-lines
10     [ "#" head? not ] filter [ " \t" split harvest ] map harvest ;
11
12 : nonstandard-mime-types ( -- assoc )
13     H{
14         { "factor" "text/plain"                       }
15         { "cgi"    "application/x-cgi-script"         }
16         { "fhtml"  "application/x-factor-server-page" }
17     } ;
18
19 ! These mime types were previously in mime.types.
20 ! Let's keep them!
21 : removed-mime-types ( -- assoc )
22     H{
23         { "pntg" "image/x-macpaint" }
24         { "m4a" "audio/mp4a-latm" }
25         { "pnt" "image/x-macpaint" }
26         { "dv" "video/x-dv" }
27         { "otm" "application/vnd.oasis.opendocument.text-master" }
28         { "mac" "image/x-macpaint" }
29         { "m4p" "audio/mp4a-latm" }
30         { "pict" "image/pict" }
31         { "scpt" "application/octet-stream" }
32         { "qti" "image/x-quicktime" }
33         { "dif" "video/x-dv" }
34         { "jp2" "image/jp2" }
35         { "qtif" "image/x-quicktime" }
36     } ;
37
38 MEMO: mime-types ( -- assoc )
39     [
40         mime-db [ unclip '[ [ _ ] dip ,, ] each ] each
41     ] H{ } make
42     nonstandard-mime-types assoc-union
43     removed-mime-types assoc-union ;
44
45 : mime-type ( filename -- mime-type )
46     file-extension mime-types at "application/octet-stream" or ;
47
48 : mime-type-encoding ( mime-type -- encoding )
49     "text/" head? utf8 binary ? ;
50