Mahoro

A simple interface to libmagic. Please install the latest version of file(1) to use this. It is most likely that your system's file is outdated and does not come with libmagic. It may be found at ftp://ftp.astron.com/pub/file/. On the two platforms I use, FreeBSD and OS X, file is located in sysutils/file in both FreeBSD Ports and DarwinPorts. Note that though this is only 0.1, I consider it fully usable, since it's just an interface.

This is Public Domain. You may do whatever you wish with the files.

Download

It's available on the RubyForge files page.

Installation

> ruby extconf.rb
> make
# make install

Reference

Mahoro.compile( path )

path is the path (or colon-separated paths) to a list of non-compiled magic databases. Compiles the files.

initialize( flags = Mahoro::NONE, path = nil )

flags may be one or a combination (bitwise or) of the following: NONE, DEBUG, SYMLINK, COMPRESS, DEVICES, MIME, CONTINUE, CHECK, PRESERVE_ATIME, RAW, ERROR. Please refer to magic(3) for more information.

path may be the path (or colon-separated paths) to a magic database. Leave nil to use the default.

file( path )

path is the path to a file. Returns the type of file as a String. To return a mimetype set the flag MIME.

buffer( input )

input is a buffer. Works just like file, except reads from input instead.

flags = flags

flags is one or a combinatino of the flags specified above.

valid?( path = nil )

path is the path (or colon-separated paths) to a magic database. Returns the validity of entries in that database.

load( path )

path is the path (or colon-separated paths) to a list of compiled magic databases. Loads the files.


All original content is in the Public Domain.