create sql module.
[biolisp.git] / lambda-utils / mime.lisp
blob31e95f95526648e60a941216c03cb15a5f6956ba
1 (in-package :lambda-utils)
3 ;;;
4 ;;; Mime Types
5 ;;;
7 (defparameter *mime-types*
8 #{"3dm" "x-world/x-3dmf"
9 "3dmf" "x-world/x-3dmf"
10 "a" "application/octet-stream"
11 "aab" "application/x-authorware-bin"
12 "aam" "application/x-authorware-map"
13 "aas" "application/x-authorware-seg"
14 "abc" "text/vnd.abc"
15 "acgi" "text/html"
16 "afl" "video/animaflex"
17 "ai" "application/postscript"
18 "aif" "audio/aiff"
19 "aifc" "audio/aiff"
20 "aiff" "audio/aiff"
21 "aim" "application/x-aim"
22 "aip" "text/x-audiosoft-intra"
23 "ani" "application/x-navi-animation"
24 "aos" "application/x-nokia-9000-communicator-add-on-software"
25 "aps" "application/mime"
26 "arj" "application/arj"
27 "art" "image/x-jg"
28 "asf" "video/x-ms-asf"
29 "asm" "text/x-asm"
30 "asp" "text/asp"
31 "asx" "video/x-ms-asf"
32 "au" "audio/basic"
33 "avi" "video/avi"
34 "avs" "video/avs-video"
35 "bcpio" "application/x-bcpio"
36 "bin" "application/octet-stream"
37 "bm" "image/bmp"
38 "bmp" "image/bmp"
39 "boo" "application/book"
40 "book" "application/book"
41 "boz" "application/x-bzip2"
42 "bsh" "application/x-bsh"
43 "bz" "application/x-bzip"
44 "bz2" "application/x-bzip2"
45 "c" "text/plain"
46 "c++" "text/plain"
47 "cc" "text/plain"
48 "ccad" "application/clariscad"
49 "cco" "application/x-cocoa"
50 "cdf" "application/cdf"
51 "cer" "application/x-x509-ca-cert"
52 "cha" "application/x-chat"
53 "chat" "application/x-chat"
54 "class" "application/java-byte-code"
55 "csv" "text/comma-separated-value"
56 "com" "application/octet-stream"
57 "conf" "text/plain"
58 "cpio" "application/x-cpio"
59 "cpp" "text/x-c"
60 "cpt" "application/mac-compactpro"
61 "crl" "application/pkcs-crl"
62 "crt" "application/x-x509-user-cert"
63 "csh" "application/x-csh"
64 "css" "text/css"
65 "cxx" "text/plain"
66 "dat" "text/plain"
67 "dcr" "application/x-director"
68 "deepv" "application/x-deepv"
69 "def" "text/plain"
70 "der" "application/x-x509-ca-cert"
71 "dif" "video/x-dv"
72 "dir" "application/x-director"
73 "dl" "video/dl"
74 "dl" "video/x-dl"
75 "doc" "application/msword"
76 "dot" "application/msword"
77 "dp" "application/commonground"
78 "drw" "application/drafting"
79 "dump" "application/octet-stream"
80 "dv" "video/x-dv"
81 "dvi" "application/x-dvi"
82 "dwf" "model/vnd.dwf"
83 "dwg" "application/acad"
84 "dxf" "application/dxf"
85 "dxr" "application/x-director"
86 "el" "text/x-script.elisp"
87 "elc" "application/x-bytecode.elisp"
88 "elc" "application/x-elc"
89 "env" "application/x-envoy"
90 "eps" "application/postscript"
91 "es" "application/x-esrehber"
92 "etx" "text/x-setext"
93 "evy" "application/envoy"
94 "exe" "application/octet-stream"
95 "f" "text/plain"
96 "f77" "text/x-fortran"
97 "f90" "text/x-fortran"
98 "fdf" "application/vnd.fdf"
99 "fif" "application/fractals"
100 "fif" "image/fif"
101 "fli" "video/fli"
102 "fli" "video/x-fli"
103 "flo" "image/florian"
104 "flx" "text/vnd.fmi.flexstor"
105 "fmf" "video/x-atomic3d-feature"
106 "for" "text/plain"
107 "for" "text/x-fortran"
108 "fpx" "image/vnd.fpx"
109 "frl" "application/freeloader"
110 "funk" "audio/make"
111 "g" "text/plain"
112 "g3" "image/g3fax"
113 "gif" "image/gif"
114 "gl" "video/gl"
115 "gl" "video/x-gl"
116 "gsd" "audio/x-gsm"
117 "gsm" "audio/x-gsm"
118 "gsp" "application/x-gsp"
119 "gss" "application/x-gss"
120 "gtar" "application/x-gtar"
121 "gz" "application/x-gzip"
122 "gzip" "application/x-gzip"
123 "h" "text/plain"
124 "hdf" "application/x-hdf"
125 "help" "application/x-helpfile"
126 "hgl" "application/vnd.hp-hpgl"
127 "hh" "text/plain"
128 "hh" "text/x-h"
129 "hlb" "text/x-script"
130 "hlp" "application/x-helpfile"
131 "hpg" "application/vnd.hp-hpgl"
132 "hpgl" "application/vnd.hp-hpgl"
133 "hqx" "application/binhex"
134 "hta" "application/hta"
135 "htc" "text/x-component"
136 "htm" "text/html"
137 "html" "text/html"
138 "htmls" "text/html"
139 "htt" "text/webviewhtml"
140 "htx" "text/html"
141 "ice" "x-conference/x-cooltalk"
142 "ico" "image/x-icon"
143 "idc" "text/plain"
144 "ief" "image/ief"
145 "iefs" "image/ief"
146 "iges" "application/iges"
147 "igs" "application/iges"
148 "ima" "application/x-ima"
149 "imap" "application/x-httpd-imap"
150 "inf" "application/inf"
151 "ins" "application/x-internett-signup"
152 "ip" "application/x-ip2"
153 "isu" "video/x-isvideo"
154 "it" "audio/it"
155 "iv" "application/x-inventor"
156 "ivr" "i-world/i-vrml"
157 "ivy" "application/x-livescreen"
158 "jam" "audio/x-jam"
159 "jav" "text/plain"
160 "java" "text/plain"
161 "jcm" "application/x-java-commerce"
162 "jfif" "image/jpeg"
163 "jfif-tb" "image/jpeg"
164 "jpe" "image/jpeg"
165 "jpeg" "image/jpeg"
166 "jpg" "image/jpeg"
167 "jps" "image/x-jps"
168 "js" "application/x-javascript"
169 "jut" "image/jutvision"
170 "kar" "audio/midi"
171 "ksh" "application/x-ksh"
172 "la" "audio/nspaudio"
173 "lam" "audio/x-liveaudio"
174 "latex" "application/x-latex"
175 "lisp" "application/x-lisp"
176 "lha" "application/lha"
177 "lhx" "application/octet-stream"
178 "list" "text/plain"
179 "lma" "audio/nspaudio"
180 "log" "text/plain"
181 "lsp" "application/x-lisp"
182 "lst" "text/plain"
183 "lsx" "text/x-la-asf"
184 "ltx" "application/x-latex"
185 "lzh" "application/x-lzh"
186 "lzx" "application/lzx"
187 "lzx" "application/x-lzx"
188 "m" "text/plain"
189 "m1v" "video/mpeg"
190 "m2a" "audio/mpeg"
191 "m2v" "video/mpeg"
192 "m3u" "audio/x-mpequrl"
193 "man" "application/x-troff-man"
194 "map" "application/x-navimap"
195 "mar" "text/plain"
196 "mbd" "application/mbedlet"
197 "mc$" "application/x-magic-cap-package-1.0"
198 "mcd" "application/mcad"
199 "mcd" "application/x-mathcad"
200 "mcf" "text/mcf"
201 "mcp" "application/netmc"
202 "me" "application/x-troff-me"
203 "mht" "message/rfc822"
204 "mhtml" "message/rfc822"
205 "mid" "application/x-midi"
206 "mid" "audio/midi"
207 "midi" "audio/midi"
208 "mif" "application/x-frame"
209 "mime" "www/mime"
210 "mjf" "audio/x-vnd.audioexplosion.mjuicemediafile"
211 "mjpg" "video/x-motion-jpeg"
212 "mm" "application/base64"
213 "mme" "application/base64"
214 "mod" "audio/mod"
215 "moov" "video/quicktime"
216 "mov" "video/quicktime"
217 "movie" "video/x-sgi-movie"
218 "mp2" "audio/mpeg"
219 "mp3" "video/mpeg"
220 "mpa" "audio/mpeg"
221 "mpc" "application/x-project"
222 "mpe" "video/mpeg"
223 "mpeg" "video/mpeg"
224 "mpg" "video/mpeg"
225 "mpga" "audio/mpeg"
226 "mpp" "application/vnd.ms-project"
227 "mpt" "application/x-project"
228 "mpv" "application/x-project"
229 "mpx" "application/x-project"
230 "mrc" "application/marc"
231 "ms" "application/x-troff-ms"
232 "mv" "video/x-sgi-movie"
233 "my" "audio/make"
234 "mzz" "application/x-vnd.audioexplosion.mzz"
235 "nap" "image/naplps"
236 "naplps"" image/naplps"
237 "nc" "application/x-netcdf"
238 "ncm" "application/vnd.nokia.configuration-message"
239 "nif" "image/x-niff"
240 "niff" "image/x-niff"
241 "nix" "application/x-mix-transfer"
242 "nsc" "application/x-conference"
243 "nvd" "application/x-navidoc"
244 "o" "application/octet-stream"
245 "oda" "application/oda"
246 "omc" "application/x-omc"
247 "omcd" "application/x-omcdatamaker"
248 "omcr" "application/x-omcregerator"
249 "p" "text/x-pascal"
250 "p10" "application/pkcs10"
251 "p12" "application/pkcs-12"
252 "p7a" "application/x-pkcs7-signature"
253 "p7c" "application/pkcs7-mime"
254 "p7m" "application/pkcs7-mime"
255 "p7r" "application/x-pkcs7-certreqresp"
256 "p7s" "application/pkcs7-signature"
257 "part" "application/pro_eng"
258 "pas" "text/pascal"
259 "pbm" "image/x-portable-bitmap"
260 "pcl" "application/x-pcl"
261 "pct" "image/x-pict"
262 "pcx" "image/x-pcx"
263 "pdb" "chemical/x-pdb"
264 "pdf" "application/pdf"
265 "pfunk" "audio/make"
266 "pfunk" "audio/make.my.funk"
267 "pgm" "image/x-portable-graymap"
268 "pic" "image/pict"
269 "pict" "image/pict"
270 "pkg" "application/x-newton-compatible-pkg"
271 "pko" "application/vnd.ms-pki.pko"
272 "pl" "text/plain"
273 "pl" "text/x-script.perl"
274 "plx" "application/x-pixclscript"
275 "pm" "image/x-xpixmap"
276 "pm" "text/x-script.perl-module"
277 "pm4" "application/x-pagemaker"
278 "pm5" "application/x-pagemaker"
279 "png" "image/png"
280 "pnm" "image/x-portable-anymap"
281 "pot" "application/mspowerpoint"
282 "pov" "model/x-pov"
283 "ppa" "application/vnd.ms-powerpoint"
284 "ppm" "image/x-portable-pixmap"
285 "pps" "application/mspowerpoint"
286 "pps" "application/vnd.ms-powerpoint"
287 "ppt" "application/mspowerpoint"
288 "ppz" "application/mspowerpoint"
289 "pre" "application/x-freelance"
290 "prt" "application/pro_eng"
291 "ps" "application/postscript"
292 "psd" "application/octet-stream"
293 "pvu" "paleovu/x-pv"
294 "pwz" "application/vnd.ms-powerpoint"
295 "py" "text/x-script.phyton"
296 "pyc" "applicaiton/x-bytecode.python"
297 "qcp" "audio/vnd.qcelp"
298 "qd3" "x-world/x-3dmf"
299 "qd3d" "x-world/x-3dmf"
300 "qif" "image/x-quicktime"
301 "qt" "video/quicktime"
302 "qtc" "video/x-qtc"
303 "qti" "image/x-quicktime"
304 "qtif" "image/x-quicktime"
305 "ra" "audio/x-realaudio"
306 "ram" "audio/x-pn-realaudio"
307 "ras" "image/cmu-raster"
308 "rast" "image/cmu-raster"
309 "rexx" "text/x-script.rexx"
310 "rf" "image/vnd.rn-realflash"
311 "rgb" "image/x-rgb"
312 "rm" "audio/x-pn-realaudio"
313 "rmi" "audio/mid"
314 "rmm" "audio/x-pn-realaudio"
315 "rmp" "audio/x-pn-realaudio"
316 "rng" "application/ringing-tones"
317 "rnx" "application/vnd.rn-realplayer"
318 "roff" "application/x-troff"
319 "rp" "image/vnd.rn-realpix"
320 "rpm" "audio/x-pn-realaudio-plugin"
321 "rt" "text/richtext"
322 "rtf" "text/richtext"
323 "rtx" "text/richtext"
324 "rv" "video/vnd.rn-realvideo"
325 "s" "text/x-asm"
326 "s3m" "audio/s3m"
327 "saveme" "application/octet-stream"
328 "sbk" "application/x-tbook"
329 "scm" "text/x-script.scheme"
330 "scm" "video/x-scm"
331 "sdml" "text/plain"
332 "sdp" "application/sdp"
333 "sdr" "application/sounder"
334 "sea" "application/sea"
335 "set" "application/set"
336 "sgm" "text/sgml"
337 "sgml" "text/sgml"
338 "sh" "application/x-sh"
339 "shar" "application/x-shar"
340 "shtml" "text/html"
341 "sid" "audio/x-psid"
342 "sit" "application/x-stuffit"
343 "skd" "application/x-koan"
344 "skm" "application/x-koan"
345 "skp" "application/x-koan"
346 "skt" "application/x-koan"
347 "sl" "application/x-seelogo"
348 "smi" "application/smil"
349 "smil" "application/smil"
350 "snd" "audio/basic"
351 "snd" "audio/x-adpcm"
352 "sol" "application/solids"
353 "spc" "application/x-pkcs7-certificates"
354 "spl" "application/futuresplash"
355 "spr" "application/x-sprite"
356 "sprite" "application/x-sprite"
357 "src" "application/x-wais-source"
358 "ssi" "text/x-server-parsed-html"
359 "ssm" "application/streamingmedia"
360 "sst" "application/vnd.ms-pki.certstore"
361 "step" "application/step"
362 "stl" "application/x-navistyle"
363 "stp" "application/step"
364 "sv4cpio"" application/x-sv4cpio"
365 "sv4crc"" application/x-sv4crc"
366 "svf" "image/x-dwg"
367 "svr" "application/x-world"
368 "swf" "application/x-shockwave-flash"
369 "t" "application/x-troff"
370 "talk" "text/x-speech"
371 "tar" "application/x-tar"
372 "tbk" "application/toolbook"
373 "tbk" "application/x-tbook"
374 "tcl" "application/x-tcl"
375 "tcsh" "text/x-script.tcsh"
376 "tex" "application/x-tex"
377 "texi" "application/x-texinfo"
378 "texinfo" "application/x-texinfo"
379 "text" "text/plain"
380 "tgz" "application/gnutar"
381 "tif" "image/tiff"
382 "tiff" "image/tiff"
383 "tr" "application/x-troff"
384 "tsi" "audio/tsp-audio"
385 "tsp" "audio/tsplayer"
386 "tsv" "text/tab-separated-values"
387 "turbot" "image/florian"
388 "txt" "text/plain"
389 "uil" "text/x-uil"
390 "uni" "text/uri-list"
391 "unis" "text/uri-list"
392 "unv" "application/i-deas"
393 "uri" "text/uri-list"
394 "uris" "text/uri-list"
395 "ustar" "application/x-ustar"
396 "uu" "text/x-uuencode"
397 "uue" "text/x-uuencode"
398 "vcd" "application/x-cdlink"
399 "vcs" "text/x-vcalendar"
400 "vda" "application/vda"
401 "vdo" "video/vdo"
402 "vew" "application/groupwise"
403 "viv" "video/vivo"
404 "vivo" "video/vivo"
405 "vmd" "application/vocaltec-media-desc"
406 "vmf" "application/vocaltec-media-file"
407 "voc" "audio/voc"
408 "vos" "video/vosaic"
409 "vox" "audio/voxware"
410 "vqe" "audio/x-twinvq-plugin"
411 "vqf" "audio/x-twinvq"
412 "vql" "audio/x-twinvq-plugin"
413 "vrml" "model/vrml"
414 "vrt" "x-world/x-vrt"
415 "vsd" "application/x-visio"
416 "vst" "application/x-visio"
417 "vsw" "application/x-visio"
418 "w60" "application/wordperfect6.0"
419 "w61" "application/wordperfect6.1"
420 "w6w" "application/msword"
421 "wav" "audio/wav"
422 "wb1" "application/x-qpro"
423 "wbmp" "image/vnd.wap.wbmp"
424 "web" "application/vnd.xara"
425 "wiz" "application/msword"
426 "wk1" "application/x-123"
427 "wmf" "windows/metafile"
428 "wml" "text/vnd.wap.wml"
429 "wmlc" "application/vnd.wap.wmlc"
430 "wmls" "text/vnd.wap.wmlscript"
431 "wmlsc" "application/vnd.wap.wmlscriptc"
432 "word" "application/msword"
433 "wp" "application/wordperfect"
434 "wp5" "application/wordperfect"
435 "wp5" "application/wordperfect6.0"
436 "wp6" "application/wordperfect"
437 "wpd" "application/wordperfect"
438 "wq1" "application/x-lotus"
439 "wri" "application/mswrite"
440 "wrl" "model/vrml"
441 "wrz" "model/vrml"
442 "wsc" "text/scriplet"
443 "wsrc" "application/x-wais-source"
444 "wtk" "application/x-wintalk"
445 "xbm" "image/x-xbitmap"
446 "xdr" "video/x-amt-demorun"
447 "xgz" "xgl/drawing"
448 "xif" "image/vnd.xiff"
449 "xl" "application/excel"
450 "xla" "application/excel"
451 "xlb" "application/excel"
452 "xlc" "application/excel"
453 "xld" "application/excel"
454 "xlk" "application/excel"
455 "xll" "application/excel"
456 "xlm" "application/excel"
457 "xls" "application/excel"
458 "xlt" "application/excel"
459 "xlv" "application/excel"
460 "xlw" "application/excel"
461 "xm" "audio/xm"
462 "xml" "text/xml"
463 "xmz" "xgl/movie"
464 "xpix" "application/x-vnd.ls-xpix"
465 "xpm" "image/xpm"
466 "x-png" "image/png"
467 "xsr" "video/x-amt-showrun"
468 "xwd" "image/x-xwd"
469 "xyz" "chemical/x-pdb"
470 "z" "application/x-compressed"
471 "zip" "application/zip"
472 "zoo" "application/octet-stream"
473 "zsh" "text/x-script.zsh"})
476 (defun mime-type (filename)
477 (or (gethash (pathname-type (pathname filename)) *mime-types*)
478 "application/octet-stream"))
481 ;; typed open
484 (defparameter *mime-handlers* #{
485 "application/octet-stream" :binary
486 "application/x-sprite" :binary
487 "application/x-sv4crc" :binary
488 "image/florian" :binary
489 "image/naplps" :binary
490 "application/x-sv4cpio" :binary
491 "application/x-texinfo" :binary
492 "applicaiton/x-bytecode.python" :binary
493 "application/acad" :binary
494 "application/arj" :binary
495 "application/base64" :binary
496 "application/binhex" :binary
497 "application/book" :binary
498 "application/cdf" :binary
499 "application/clariscad" :binary
500 "application/commonground" :binary
501 "application/drafting" :binary
502 "application/dxf" :binary
503 "application/envoy" :binary
504 "application/excel" :binary
505 "application/fractals" :binary
506 "application/freeloader" :binary
507 "application/futuresplash" :binary
508 "application/gnutar" :binary
509 "application/groupwise" :binary
510 "application/hta" :binary
511 "application/i-deas" :binary
512 "application/iges" :binary
513 "application/inf" :binary
514 "application/java-byte-code" :binary
515 "application/lha" :binary
516 "application/lzx" :binary
517 "application/mac-compactpro" :binary
518 "application/marc" :binary
519 "application/mbedlet" :binary
520 "application/mcad" :binary
521 "application/mime" :binary
522 "application/mspowerpoint" :binary
523 "application/msword" :binary
524 "application/mswrite" :binary
525 "application/netmc" :binary
526 "application/octet-stream" :binary
527 "application/oda" :binary
528 "application/pdf" :binary
529 "application/pkcs-12" :binary
530 "application/pkcs-crl" :binary
531 "application/pkcs10" :binary
532 "application/pkcs7-mime" :binary
533 "application/pkcs7-signature" :binary
534 "application/pkix-cert" :binary
535 "application/postscript" :binary
536 "application/pro_eng" :binary
537 "application/ringing-tones" :binary
538 "application/sdp" :binary
539 "application/sea" :binary
540 "application/set" :binary
541 "application/smil" :binary
542 "application/solids" :binary
543 "application/sounder" :binary
544 "application/step" :binary
545 "application/streamingmedia" :binary
546 "application/toolbook" :binary
547 "application/vda" :binary
548 "application/vnd.fdf" :binary
549 "application/vnd.hp-hpgl" :binary
550 "application/vnd.ms-pki.certstore" :binary
551 "application/vnd.ms-pki.pko" :binary
552 "application/vnd.ms-powerpoint" :binary
553 "application/vnd.ms-project" :binary
554 "application/vnd.nokia.configuration-message" :binary
555 "application/vnd.rn-realplayer" :binary
556 "application/vnd.wap.wmlc" :binary
557 "application/vnd.wap.wmlscriptc" :binary
558 "application/vnd.xara" :binary
559 "application/vocaltec-media-desc" :binary
560 "application/vocaltec-media-file" :binary
561 "application/wordperfect" :binary
562 "application/wordperfect6.0" :binary
563 "application/wordperfect6.1" :binary
564 "application/x-123" :binary
565 "application/x-aim" :binary
566 "application/x-authorware-bin" :binary
567 "application/x-authorware-map" :binary
568 "application/x-authorware-seg" :binary
569 "application/x-bcpio" :binary
570 "application/x-bsh" :binary
571 "application/x-bytecode.elisp" :binary
572 "application/x-bzip" :binary
573 "application/x-bzip2" :binary
574 "application/x-cdlink" :binary
575 "application/x-chat" :binary
576 "application/x-cocoa" :binary
577 "application/x-compressed" :binary
578 "application/x-conference" :binary
579 "application/x-cpio" :binary
580 "application/x-csh" :binary
581 "application/x-deepv" :binary
582 "application/x-director" :binary
583 "application/x-dvi" :binary
584 "application/x-elc" :binary
585 "application/x-envoy" :binary
586 "application/x-esrehber" :binary
587 "application/x-frame" :binary
588 "application/x-freelance" :binary
589 "application/x-gsp" :binary
590 "application/x-gss" :binary
591 "application/x-gtar" :binary
592 "application/x-hdf" :binary
593 "application/x-helpfile" :binary
594 "application/x-httpd-imap" :binary
595 "application/x-ima" :binary
596 "application/x-internett-signup" :binary
597 "application/x-inventor" :binary
598 "application/x-ip2" :binary
599 "application/x-java-commerce" :binary
600 "application/x-javascript" :binary
601 "application/x-koan" :binary
602 "application/x-livescreen" :binary
603 "application/x-lotus" :binary
604 "application/x-lzh" :binary
605 "application/x-lzx" :binary
606 "application/x-magic-cap-package-1.0" :binary
607 "application/x-mathcad" :binary
608 "application/x-midi" :binary
609 "application/x-mix-transfer" :binary
610 "application/x-navi-animation" :binary
611 "application/x-navidoc" :binary
612 "application/x-navimap" :binary
613 "application/x-navistyle" :binary
614 "application/x-netcdf" :binary
615 "application/x-newton-compatible-pkg" :binary
616 "application/x-nokia-9000-communicator-add-on-software" :binary
617 "application/x-omc" :binary
618 "application/x-omcdatamaker" :binary
619 "application/x-omcregerator" :binary
620 "application/x-pagemaker" :binary
621 "application/x-pcl" :binary
622 "application/x-pixclscript" :binary
623 "application/x-pkcs7-certificates" :binary
624 "application/x-pkcs7-certreqresp" :binary
625 "application/x-pkcs7-signature" :binary
626 "application/x-project" :binary
627 "application/x-qpro" :binary
628 "application/x-seelogo" :binary
629 "application/x-shockwave-flash" :binary
630 "application/x-sprite" :binary
631 "application/x-stuffit" :binary
632 "application/x-tar" :binary
633 "application/x-tbook" :binary
634 "application/x-tcl" :binary
635 "application/x-texinfo" :binary
636 "application/x-troff" :binary
637 "application/x-troff-man" :binary
638 "application/x-troff-me" :binary
639 "application/x-troff-ms" :binary
640 "application/x-ustar" :binary
641 "application/x-visio" :binary
642 "application/x-vnd.audioexplosion.mzz" :binary
643 "application/x-vnd.ls-xpix" :binary
644 "application/x-wais-source" :binary
645 "application/x-wintalk" :binary
646 "application/x-world" :binary
647 "application/x-x509-ca-cert" :binary
648 "application/x-x509-user-cert" :binary
649 "audio/aiff" :binary
650 "audio/basic" :binary
651 "audio/it" :binary
652 "audio/make" :binary
653 "audio/make.my.funk" :binary
654 "audio/mid" :binary
655 "audio/midi" :binary
656 "audio/mod" :binary
657 "audio/mpeg" :binary
658 "audio/nspaudio" :binary
659 "audio/s3m" :binary
660 "audio/tsp-audio" :binary
661 "audio/tsplayer" :binary
662 "audio/vnd.qcelp" :binary
663 "audio/voc" :binary
664 "audio/voxware" :binary
665 "audio/wav" :binary
666 "audio/x-adpcm" :binary
667 "audio/x-gsm" :binary
668 "audio/x-jam" :binary
669 "audio/x-liveaudio" :binary
670 "audio/x-mpequrl" :binary
671 "audio/x-pn-realaudio" :binary
672 "audio/x-pn-realaudio-plugin" :binary
673 "audio/x-psid" :binary
674 "audio/x-realaudio" :binary
675 "audio/x-twinvq" :binary
676 "audio/x-twinvq-plugin" :binary
677 "audio/x-vnd.audioexplosion.mjuicemediafile" :binary
678 "audio/xm" :binary
679 "chemical/x-pdb" :binary
680 "i-world/i-vrml" :binary
681 "image/bmp" :binary
682 "image/cmu-raster" :binary
683 "image/fif" :binary
684 "image/florian" :binary
685 "image/g3fax" :binary
686 "image/gif" :binary
687 "image/ief" :binary
688 "image/jpeg" :binary
689 "image/jutvision" :binary
690 "image/naplps" :binary
691 "image/pict" :binary
692 "image/png" :binary
693 "image/tiff" :binary
694 "image/vnd.fpx" :binary
695 "image/vnd.rn-realflash" :binary
696 "image/vnd.rn-realpix" :binary
697 "image/vnd.wap.wbmp" :binary
698 "image/vnd.xiff" :binary
699 "image/x-dwg" :binary
700 "image/x-icon" :binary
701 "image/x-jg" :binary
702 "image/x-jps" :binary
703 "image/x-niff" :binary
704 "image/x-pcx" :binary
705 "image/x-pict" :binary
706 "image/x-portable-anymap" :binary
707 "image/x-portable-bitmap" :binary
708 "image/x-portable-graymap" :binary
709 "image/x-portable-pixmap" :binary
710 "image/x-quicktime" :binary
711 "image/x-rgb" :binary
712 "image/x-xbitmap" :binary
713 "image/x-xpixmap" :binary
714 "image/x-xwd" :binary
715 "image/xpm" :binary
716 "message/rfc822" :binary
717 "model/vnd.dwf" :binary
718 "model/vrml" :binary
719 "model/x-pov" :binary
720 "paleovu/x-pv" :binary
721 "video/animaflex" :binary
722 "video/avi" :binary
723 "video/avs-video" :binary
724 "video/dl" :binary
725 "video/fli" :binary
726 "video/gl" :binary
727 "video/mpeg" :binary
728 "video/quicktime" :binary
729 "video/vdo" :binary
730 "video/vivo" :binary
731 "video/vnd.rn-realvideo" :binary
732 "video/vosaic" :binary
733 "video/x-amt-demorun" :binary
734 "video/x-amt-showrun" :binary
735 "video/x-atomic3d-feature" :binary
736 "video/x-dl" :binary
737 "video/x-dv" :binary
738 "video/x-fli" :binary
739 "video/x-gl" :binary
740 "video/x-isvideo" :binary
741 "video/x-motion-jpeg" :binary
742 "video/x-ms-asf" :binary
743 "video/x-qtc" :binary
744 "video/x-scm" :binary
745 "video/x-sgi-movie" :binary
746 "windows/metafile" :binary
747 "www/mime" :binary
748 "x-conference/x-cooltalk" :binary
749 "x-world/x-3dmf" :binary
750 "x-world/x-vrt" :binary
751 "xgl/drawing" :binary
752 "xgl/movie" :binary
753 "text/comma-separated-value" :text
754 "application/x-ksh" :text
755 "application/x-tex" :text
756 "application/x-latex" :text
757 "application/x-lisp" :text
758 "application/x-sh" :text
759 "application/x-shar" :text
760 "text/asp" :text
761 "text/css" :text
762 "text/html" :text
763 "text/mcf" :text
764 "text/pascal" :text
765 "text/plain" :text
766 "text/richtext" :text
767 "text/scriplet" :text
768 "text/sgml" :text
769 "text/tab-separated-values" :text
770 "text/uri-list" :text
771 "text/vnd.abc" :text
772 "text/vnd.fmi.flexstor" :text
773 "text/vnd.wap.wml" :text
774 "text/vnd.wap.wmlscript" :text
775 "text/webviewhtml" :text
776 "text/x-asm" :text
777 "text/x-audiosoft-intra" :text
778 "text/x-c" :text
779 "text/x-component" :text
780 "text/x-fortran" :text
781 "text/x-h" :text
782 "text/x-la-asf" :text
783 "text/x-pascal" :text
784 "text/x-script" :text
785 "text/x-script.elisp" :text
786 "text/x-script.perl" :text
787 "text/x-script.perl-module" :text
788 "text/x-script.phyton" :text
789 "text/x-script.rexx" :text
790 "text/x-script.scheme" :text
791 "text/x-script.tcsh" :text
792 "text/x-script.zsh" :text
793 "text/x-server-parsed-html" :text
794 "text/x-setext" :text
795 "text/x-speech" :text
796 "text/x-uil" :text
797 "text/x-uuencode" :text
798 "text/x-vcalendar" :text
799 "text/xml" :xml
800 "application/zip" :binary
801 "application/x-gzip" :gzip})
803 (defgeneric typed-open* (filename file-type direction args)
804 (:documentation "Open file according file-type"))
806 (defmethod typed-open* (filename (file-type (eql :text)) direction args)
807 (apply #'open (nconc `(,filename :direction ,direction) args)))
809 ;; TODO: add apropriate typed-open method for xml type
810 (defmethod typed-open* (filename (file-type (eql :xml)) direction args)
811 (apply #'open (nconc `(,filename) args)))
813 (defmethod typed-open* (filename (file-type (eql :binary)) direction args)
814 (apply #'open (nconc `(,filename :element-type (unsigned-byte 8)) args)))
816 (defmethod typed-open* (filename (file-type (eql :gzip)) (direction (eql :input)) args)
817 (let ((gzip-stream
818 (make-gzip-input-stream
819 (apply #'open (nconc
820 `(,filename :element-type (unsigned-byte 8))
821 args)))))
822 (make-flexi-stream gzip-stream :external-format *default-external-format*)))
824 (defun mime-handler (mime)
825 (or (gethash mime *mime-handlers*)
826 :binary))
828 (defun typed-open (filename &rest args &key mime (direction :input) &allow-other-keys)
829 "Open file according file-type and return (values stream mime-type)"
830 (unless mime
831 (setf mime (mime-type filename)))
832 (remf args :mime)
833 (values (typed-open* filename (mime-handler mime) direction args)
834 mime))
838 ;; Util Functions
839 (defmacro with-open-typed-file ((var path &rest options)
840 &body body)
841 (let ((abortp (gensym "abort")))
842 `(let ((,var (typed-open ,path ,@options))
843 (,abortp t))
844 (unwind-protect
845 (multiple-value-prog1 (progn ,@body)
846 (setf ,abortp nil))
847 (close ,var :abort ,abortp)))))