File magic class

Is there are class for Ruby that does the same as the file command and
tell you what type of file you are looking at?

I have the Perl one but can’t find a Ruby one? Does it already exist or
should I create it?

Is there are class for Ruby that does the same as the file command and
tell you what type of file you are looking at?

I have the Perl one but can’t find a Ruby one? Does it already exist or
should I create it?

Probably there’s a more well written module but…

Here’s my version of magic.rb, which reads a magic database and
returns a string. That’s slow, ugly and not complete but at least
working on simple cases.
http://www.dm4lab.to/~kjana/ruby/magic.rb

> ruby magic.rb /bin/sh /usr/share/misc/magic
"ELF 32-bit LSB executable, Intel 80386, version 1 (FreeBSD)"
> ruby magic.rb AICbook.ps /usr/share/misc/magic 
"PostScript document text conforming at level 3.0"
> ruby magic.rb .comment /usr/share/misc/magic         
nil

Note I didn’t write any documentation and it lacks many features such
as correct treatment of relative offset of patterns or string
comparison in dictionary order.

···

In message 3E50AC20.7090400@semantico.com peter@semantico.com writes:


kjana@dm4lab.to February 17, 2003
Behind the clouds is the sun still shining.

YANAGAWA Kazuhisa wrote:

Probably there’s a more well written module but…

So far you this is the only one I’ve seen and it works fine for me. Any
chance of you submitting this into the RAA? It might not be the killer
app we all want to write but it is damn usefull and has saved me having
to go off and write my own.

Note I didn’t write any documentation and it lacks many features such
as correct treatment of relative offset of patterns or string
comparison in dictionary order.

Thats version 1 for you.