Class: Mahoro

Inherits:
Object
  • Object
show all
Defined in:
ext/mahoro/mahoro.c

Defined Under Namespace

Modules: ThreadSafe Classes: Error

Constant Summary collapse

NONE =

No special handling, the default

INT2FIX(MAGIC_NONE)
DEBUG =

print debugging messages to stderr

INT2FIX(MAGIC_DEBUG)
INT2FIX(MAGIC_SYMLINK)
COMPRESS =

Check inside compressed files

INT2FIX(MAGIC_COMPRESS)
DEVICES =

Look at the contents of devices

INT2FIX(MAGIC_DEVICES)
MIME_TYPE =

Return only the MIME type This constant may not be defined on older systems.

INT2FIX(MAGIC_MIME_TYPE)
CONTINUE =

Return all matches

INT2FIX(MAGIC_CONTINUE)
CHECK =

Check the magic database for consistency and print warnings to stderr

INT2FIX(MAGIC_CHECK)
PRESERVE_ATIME =

preserve access time of files analyzed

INT2FIX(MAGIC_PRESERVE_ATIME)
RAW =

Don’t translate unprintable characters to a \ooo octal representation

INT2FIX(MAGIC_RAW)
ERROR =

Treat operating system errors while trying to open files and follow symlinks as real errors, instead of printing them in the magic buffer.

INT2FIX(MAGIC_ERROR)
MIME_ENCODING =

Return a MIME encoding, instead of a textual description. This constant may not be defined on older systems.

INT2FIX(MAGIC_MIME_ENCODING)
MIME =

return both MIME type and encoding

INT2FIX(MAGIC_MIME)
APPLE =

Return both Apple creator and type. This constant may not be defined on older systems.

INT2FIX(MAGIC_APPLE)
NO_CHECK_COMPRESS =

Don’t check for or inside compressed files. This constant may not be defined on older systems.

INT2FIX(MAGIC_NO_CHECK_COMPRESS)
NO_CHECK_TAR =

Don’t examine tar files. This constant may not be defined on older systems.

INT2FIX(MAGIC_NO_CHECK_TAR)
NO_CHECK_SOFT =

Don’t consult magic files. This constant may not be defined on older systems.

INT2FIX(MAGIC_NO_CHECK_SOFT)
NO_CHECK_APPTYPE =

Don’t check application type (EMX only). This constant may not be defined on older systems.

INT2FIX(MAGIC_NO_CHECK_APPTYPE)
NO_CHECK_ELF =

Don’t check for ELF details. This constant may not be defined on older systems.

INT2FIX(MAGIC_NO_CHECK_ELF)
NO_CHECK_TEXT =

Don’t check for various types of ASCII text files. This constant may not be defined on older systems.

INT2FIX(MAGIC_NO_CHECK_ASCII)
NO_CHECK_TOKENS =

Don’t check for known tokens inside ASCII files. This constant may not be defined on older systems.

INT2FIX(MAGIC_NO_CHECK_TOKENS)
NO_CHECK_ENCODING =

Don’t check for text encodings. This constant may not be defined on older systems.

INT2FIX(MAGIC_NO_CHECK_ENCODING)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeObject

Mahoro.new(flags = Mahoro::NONE, path = nil) -> mahoro_obj

Create and initialize a new Mahoro object.

flags may be one or more of any combination of the Mahoro

constants

supported by Mahoro#flags=. path (if not nil) is a colon-separated list of database files, see Mahoro#load.

If path is not given (or nil), the default database is used. Consult your libmagic(3) documentation for the location of that file as it varies by installation.



71
72
73
# File 'ext/mahoro/mahoro.c', line 71

static VALUE
mahoro_initialize(argc, argv, self)
int argc;

Class Method Details

.compileObject

Mahoro.compile(path) -> true

This is a wrapper around the Mahoro#compile instance method, but does not require an existing Mahoro object. Use the instance method unless you only need to test the validity of a magic(5) database.



309
310
311
# File 'ext/mahoro/mahoro.c', line 309

static VALUE
mahoro_s_compile(klass, path)
VALUE klass, path;

Instance Method Details

#bufferObject

mahoro_obj.buffer(buffer) -> String

Returns a textual description of the contents of the buffer given. buffer should be a String object. Use Mahoro#file instead of this method if the contents is not already in memory (and possibly too large to fit into memory). Raises Mahoro::Error on failed lookups.



158
159
160
# File 'ext/mahoro/mahoro.c', line 158

static VALUE
mahoro_buffer(self, input)
VALUE self, input;

#compileObject

mahoro_obj.compile(path) -> true

Compile the the colon separated list of database files passed in as path. It returns true on success and raises Mahoro::Error on failure. Compiled files created are named from the File.basename of each file argument with “.mgc” appended to it.

There is no need to use this function if you are using the default magic(5) database on your operating system. This is only needed if you require additional magic not in the default magic database.

Users of this method are likely to need Mahoro#load (and vice-versa).



284
285
286
# File 'ext/mahoro/mahoro.c', line 284

static VALUE
mahoro_compile(self, path)
VALUE self, path;

#fileObject

mahoro_obj.file(filename) -> String

Returns a textual description of the contents of the filename given. Use Mahoro#buffer instead of this method if the contents of your file is already in memory. Raises Mahoro::Error on failed lookups.



125
126
127
# File 'ext/mahoro/mahoro.c', line 125

static VALUE
mahoro_file(self, path)
VALUE self, path;

#flags=Object

mahoro_obj.flags = flags

Change the behavior of an already-initialized Mahoro object. The behavior of a Mahoro object is specified at load time, but may be changed after-the-fact. flags is a bitwise (OR) mask of one or more of the following constants in the Mahoro namespace:

  • APPLE

  • CHECK

  • COMPRESS

  • CONTINUE

  • DEBUG

  • DEVICES

  • ERROR

  • MIME

  • MIME_ENCODING

  • MIME_TYPE

  • NONE

  • NO_CHECK_APPTYPE

  • NO_CHECK_COMPRESS

  • NO_CHECK_ELF

  • NO_CHECK_ENCODING

  • NO_CHECK_SOFT

  • NO_CHECK_TAR

  • NO_CHECK_TEXT

  • NO_CHECK_TOKENS

  • PRESERVE_ATIME

  • RAW

  • SYMLINK



208
209
210
# File 'ext/mahoro/mahoro.c', line 208

static VALUE
mahoro_set_flags(self, flags)
VALUE self, flags;

#loadObject

mahoro_obj.load(path) -> mahoro_obj

Used to load the the colon-separated list of database files (path). The “.mgc” suffix will be added to each filename where appropriate. This will raise Mahoro::Error on failure.

There is no need to use this function if you are using the default magic(5) database on your operating system. This is only needed if you require additional magic not in the default magic database.

The default database file is named by the MAGIC environment variable. Consult your libmagic installation documentation for the location of your default database file name.

Users of this method are likely to need Mahoro#compile (and vice-versa).



336
337
338
# File 'ext/mahoro/mahoro.c', line 336

static VALUE
mahoro_load(self, path)
VALUE self, path;

#valid?Boolean

mahoro_obj.check(path = nil) -> true or false

This is used to check the validity of entries in the colon separated database files passed in as path. If path is not passed (or nil), this will check the default database.

Returns:

  • (Boolean)


234
235
236
# File 'ext/mahoro/mahoro.c', line 234

static VALUE
mahoro_check(argc, argv, self)
int argc;