Tuesday, February 24, 2009

ffiruby-filemagic

Win32 Support? sorry.

A new implementation of the ancient ruby-filemagic gem (http://grub.ath.cx/filemagic/).
This version uses FFI to talk to the native library (JRuby friendly).
(Blurb from the original gem site follows)

What is FileMagic?

FileMagic is a Ruby binding to the magic(4) library, which you may know better as the file(1) command. The file command identifies the type of a file using, among other tests, a test for whether the file begins with a certain magic number.

Install:
Make sure you have the magic(4) library installed.

> sudo gem sources -a http://gems.github.com
> sudo gem install glongman-ffiruby-filemagic

After Install:

> sudo ffi_file_magic_setup
> irb
>> require 'ffi_file_magic'
=> true
>> fm = FFIFileMagic.new(FFIFileMagic::MAGIC_MIME)
=> #<FFIFileMagic:0x11a4d9c @cookie=#<Native Pointer address=0x13606f0>>
>> fm.file('rails.png') #supply a path to your own image
=> "image/png"
>>

http://github.com/glongman/ffiruby-filemagic/tree/master

No comments: