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 ;
8 MEMO: mime-db ( -- seq )
9 "vocab:mime/types/mime.types" ascii file-lines
10 [ "#" head? ] reject [ " \t" split harvest ] map harvest ;
12 : nonstandard-mime-types ( -- assoc )
14 { "factor" "text/plain" }
15 { "cgi" "application/x-cgi-script" }
16 { "fhtml" "application/x-factor-server-page" }
19 ! These mime types were previously in mime.types.
21 : removed-mime-types ( -- assoc )
23 { "pntg" "image/x-macpaint" }
24 { "m4a" "audio/mp4a-latm" }
25 { "pnt" "image/x-macpaint" }
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" }
35 { "qtif" "image/x-quicktime" }
38 MEMO: mime-types ( -- assoc )
40 mime-db [ unclip '[ [ _ ] dip ,, ] each ] each
42 nonstandard-mime-types assoc-union
43 removed-mime-types assoc-union ;
45 : mime-type ( filename -- mime-type )
46 file-extension mime-types at "application/octet-stream" or ;
48 : mime-type-encoding ( mime-type -- encoding )
49 "text/" head? utf8 binary ? ;