[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Determine mime type of a file
- From: Justin Cormack <justin@...>
- Date: Mon, 02 May 2011 12:00:37 +0100
On Mon, 2011-05-02 at 11:32 +0200, Marco wrote:
> On 2011-05-02 steve donovan <steve.j.donovan@gmail.com> wrote:
>
> > On Mon, May 2, 2011 at 10:55 AM, Marco <netuse@lavabit.com> wrote:
> > > How can I determine the mime type of a file (like the
> > > unix
> > > command “file -i <some_file>”)?
> >
> > Why not just this? ;)
> >
> > local type = io.popen('file -i '..myfile):read()
>
> I thought there may be a more portable solution. I think
> file -i breaks on non-unix systems.
>
> > Otherwise, you need a catalog, and that is dependent on
> > system setup on something like Gnome, which provides
> > such a thing helpfully encoded as XML.
>
> What do you mean by catalog? A file extension - mime type
> mapping? That would quickly break when a file has no
> extension (file -i is not confused by this).
There is a port of file for windows if you need it
http://gnuwin32.sourceforge.net/packages/file.htm
Also worth noting that the file command uses libmagic, you could write a
direct Lua binding to the library. But it is a unixy way of doing
things, Windows does prefer to use extensions.
Justin