[plt-scheme] Guessing the file type?

From: Amit Saha (lists.amitsaha at gmail.com)
Date: Wed Jul 29 14:16:04 EDT 2009

Amit Saha wrote:
> Marek Kubica wrote:
>> Hi,
>>
>> On Mon, 27 Jul 2009 09:24:23 +0530
>> Amit Saha <lists.amitsaha at gmail.com> wrote:
>>
>>> Great. On my Ubuntu Linux:
>>>
>>>  > ((make-path->mime-type "/etc/mime.types") (build-path 
>>> "/home/r00t/Music/" "m.mp3"))
>>> #"audio/mpeg"
>>>
>>> does it.
>>>
>>> Now wondering: How would I go about writing code, such as this- to
>>> work on Linux as well as say, a Mac OSX ?
>>
>> By checking for the OS and setting the path to the MIME Database
>> accordingly. The biggest problem I see would be Windows, which as far
>> as I know does not have such a file at all.
> 
> I took a cursory look at "mimetypes.py" 
> (http://svn.python.org/view/python/trunk/Lib/mimetypes.py?revision=72045&view=markup) 
>  - a Python module which acts as a interface with the OS MIME types. 
>  From what I see, it has the list of "known files" into which it looks 
> into for the OS recogniezed MIME types..

Another way would be to eliminate the dependency on the OS's files 
completely, by maintaining a map of the file extensions to the MIME 
type, like 
http://bazaar.launchpad.net/%7Evijay-the-schemer/spark-scheme/devel/annotate/head%3A/scheme/http/mime-types.ss

Is there a limitation to this approach, except for keeping it updated?

An obvious benefit is that this approach won't be dependent on the 
differences between Unix-es and non-Unix.

Best,
Amit

> 
> I will try to look into implementing such a solution for plt-scheme..
> 
> Best,
> Amit
>>
>> regards,
>> Marek
>>
> 
> 


-- 
email: amitsaha.in at gmail.com
Journal: http://amitksaha.wordpress.com
µ-blog: http://twitter.com/amitsaha
IRC: cornucopic on #scheme, #lisp, #math, #linux


Posted on the users mailing list.