File magic class 
Author Message
 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?



Fri, 05 Aug 2005 17:32:34 GMT  
 File magic class

Quote:

> 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.

--

Behind the clouds is the sun still shining.



Fri, 05 Aug 2005 20:10:11 GMT  
 File magic class

Quote:

> 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.

Quote:
> 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.


Fri, 05 Aug 2005 21:03:27 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Magic at class-definition time

2. class instance magic

3. any1 done a magic square in c++ using class

4. Icetips Magic Entries & Magic Buttons demo

5. Magic Numbers in *.exe file

6. ImportError: Bad magic number in .pyc file

7. fasl file magic numbers?

8. Binary filing classes bug ?

9. Bug in the class 'File'???

10. File class error mesage

11. generate class list from .h files

12. Disk based large file sort class

 

 
Powered by phpBB® Forum Software