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