FileMagic Library Binding

VERSION

This documentation refers to filemagic version 0.6.1

DESCRIPTION

FileMagic extension module. See also libmagic(3), file(1) and magic(4).

Constants

MAGIC_NONE

No flags

MAGIC_DEBUG

Turn on debugging

MAGIC_SYMLINK

Follow symlinks

MAGIC_COMPRESS

Check inside compressed files

MAGIC_DEVICES

Look at the contents of devices

MAGIC_MIME

Return a mime string

MAGIC_CONTINUE

Return all matches, not just the first

MAGIC_CHECK

Print warnings to stderr

Methods

file(filename)

Returns a textual description of the contents of the filename argument

buffer(string)

Returns a textual description of the contents of the string argument

check(filename)

Checks the validity of entries in the database file passed in as filename

compile(filename)

Compiles the database file passed in as filename

close()

Closes the magic database and frees any memory allocated

Synospis

require 'filemagic'

p FileMagic::VERSION
p FileMagic::MAGIC_VERSION

p FileMagic.new.flags

FileMagic.open(:mime) { |fm|
  p fm.flags
  p fm.file(__FILE__)
  p fm.file(__FILE__, true)

  fm.flags = [:raw, :continue]
  p fm.flags
}

fm = FileMagic.new
p fm.flags

mime = FileMagic.mime
p mime.flags

Installation

Install the gem:

sudo gem install ruby-filemagic

The file(1) library and headers are required.

LINKS

Homepage

www.darwinsys.com/file/

Documentation

blackwinter.github.com/ruby-filemagic

Source code

github.com/blackwinter/ruby-filemagic

RubyGem

rubygems.org/gems/ruby-filemagic

Travis CI

travis-ci.org/blackwinter/ruby-filemagic

AUTHORS

CREDITS

  • Martin Carpenter <mcarpenter@free.fr> for Ruby 1.9.2 compatibility and other improvements.

COPYING

The filemagic extension library is copywrited free software by Travis Whitton <tinymountain@gmail.com>. You can redistribute it under the terms specified in the COPYING file of the Ruby distribution.

WARRANTY

THIS SOFTWARE IS PROVIDED “AS IS” AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.