ruby-filemagic

by blackwinter

blackwinter / ruby-filemagic

Ruby bindings to the magic(4) library, revised.

126 Stars 26 Forks Last release: Not found 125 Commits 10 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

= FileMagic Library Binding

== VERSION

This documentation refers to filemagic version 0.7.2

== DESCRIPTION

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

=== Constants

MAGICNONE:: No flags MAGICDEBUG:: Turn on debugging MAGICSYMLINK:: Follow symlinks MAGICCOMPRESS:: Check inside compressed files MAGICDEVICES:: Look at the contents of devices MAGICMIME:: Return a mime string MAGICCONTINUE:: Return all matches, not just the first MAGICCHECK:: 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 load(filename):: Loads the database file passed in as filename close():: Closes the magic database and frees any memory allocated

=== Synopsis

require 'filemagic'

p FileMagic::VERSION # => "0.7.2" p FileMagic::MAGIC_VERSION # => "5.28"

p FileMagic.new.flags # => []

FileMagic.open(:mime) { |fm| p fm.flags # => [:mimetype, :mimeencoding] p fm.file(FILE) # => "text/plain; charset=us-ascii" p fm.file(FILE, true) # => "text/plain"

fm.flags = [:raw, :continue]
p fm.flags
# => [:continue, :raw]

}

fm = FileMagic.new p fm.flags # => []

mime = FileMagic.mime p mime.flags # => [:mimetype, :mimeencoding]

=== Environment

The environment variable +MAGIC+ can be used to set the default magic file name.

=== Installation

Install the gem:

sudo gem install ruby-filemagic

The file(1) library and headers are required:

Debian/Ubuntu:: +libmagic-dev+ Fedora/SuSE:: +file-devel+ Gentoo:: +sys-libs/libmagic+ OS X:: brew install libmagic

=== Build native extension

rake docker:gem:native

Requires Docker[https://docker.com] to be installed.

== LINKS

Homepage:: http://www.darwinsys.com/file/ Documentation:: https://blackwinter.github.com/ruby-filemagic Source code:: https://github.com/blackwinter/ruby-filemagic RubyGem:: https://rubygems.org/gems/ruby-filemagic Travis CI:: https://travis-ci.org/blackwinter/ruby-filemagic

== AUTHORS

== CREDITS

  • Martin Carpenter [email protected] for Ruby 1.9.2 compatibility and other improvements.

  • Pavel Lobashov (@ShockwaveNN) for Dockerfile to build cross-compiled Windows extension (pull request #26).

== COPYING

The filemagic extension library is copywrited free software by Travis Whitton [email protected]. 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.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.