lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello,

On Mon, 2 May 2011 11:22:14 +0200
Dirk Laurie <dpl@sun.ac.za> wrote:

> On Mon, May 02, 2011 at 10:55:23AM +0200, Marco wrote:
> > How can I determine the mime type of a file (like the unix
> > command “file -i <some_file>”)?
> > 
> Well, on my Ubuntu system it's this easy:
> 
> > function mime_type(a) return io.popen('file -i '..a):read() end
> 
> Unfortunately io.popen "is system dependent and is not available on 
> all platforms."

Another thing that could be done is binding libmagic [1], which is what
the “file” command uses internally. As a fall-back for systems not
having it, a table mapping filename extensions to MIME types could be
provided.

Cheers,

---
[1] http://linux.die.net/man/3/libmagic
-- 
Adrian Perez <aperez@igalia.com>
Igalia - Free Software Engineering

Sent from my Ecto-1.

Attachment: signature.asc
Description: PGP signature