From: kjana@...4lab.to (YANAGAWA Kazuhisa) Date: 2003-02-17T21:10:11+09:00 Subject: Re: File magic class In message <3E50AC20.7090400@semantico.com> peter@semantico.com writes: > 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. > 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. -- kjana@dm4lab.to February 17, 2003 Behind the clouds is the sun still shining.