GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  FILE::MMAGIC::XS (3)

.ds Aq ’

NAME

File::MMagic::XS - Guess File Type With XS (a la mod_mime_magic)

CONTENTS

SYNOPSIS



  use File::MMagic::XS;

  my $m = File::MMagic::XS->new();
     $m = File::MMagic::XS->new(/etc/magic); # use external magic file

  my $mime = $m->get_mime($file);

  # use File::MMagic compatible interface
  use File::MMagic::XS qw(:compat);

  my $m = File::MMagic::XS->new();
  $m->checktype_filename($file);



DESCRIPTION

This is a port of Apache2 mod_mime_magic.c in Perl, written in XS with the aim of being efficient and fast, especially for applications that need to be run for an extended amount of time.

There is a compatibility layer for File::MMagic. you can specify :compat when importing the module



   use File::MMagic::XS qw(:compat);



And then the following methods are going to be available from File::MMagic::XS:



   checktype_filename
   checktype_filehandle
   checktype_contents
   addMagicEntry



Currently this software is in beta. If you have suggestions/recommendations about the interface or anything else, now is your chance to send them!

METHODS

    new(%args)

Creates a new File::MMagic::XS object.

If you specify the file argument, then File::MMagic::XS will load magic definitions from the specified file. If unspecified, it will use the magic file that will be installed under File/MMagic/ directory.

clone()

Clones an existing File::MMagic::XS object.

    parse_magic_file($file)

Read and parse a magic file, as used by Apache2.

    get_mime($file)

Inspects the file specified by $file and returns a MIME type if possible. If no matching MIME type is found, then undef is returned.

    fsmagic($file)

Inspects a file and returns a MIME type using inode information only. The contents of the file is not inspected.

    fhmagic($fh)

Inspects a file handle and returns a mime string by reading the contents of the file handle.

    ascmagic($file)

Inspects a piece of data (assuming it’s not binary data), and attempts to determine the file type.

    bufmagic($scalar)

Inspects a scalar buffer, and attempts to determine the file type

    add_magic($magic_line)

Adds a new magic entry to the object. The format of $magic_line is the same as magic(5) file. This allows you to add custom magic entries at run time

add_file_ext($ext, CW$mime)

Adds a new file extension to MIME mapping. This is used as a fallback method to determining MIME types.



  my $magic = File::MMagic::XS->new;
  $magic->add_file_ext(t, text/perl-test);
  my $mime  = $magic->get_mime(t/01-sanity.t);



This will make get_mime() return ’text/perl-test’.

error()

Returns the last error string.

PERFORMANCE

This is on my laptop (MacBook, Core 2 Duo/ Mac OS X 10.4.3), tested against File::MMagic::XS 0.09003



          Rate  perl    xs
  perl   513/s    --  -96%
  xs   12048/s 2249%    --



SEE ALSO

File::MMagic

AUTHOR

Copyright 2005-2007 Daisuke Maki <daisuke@endeworks.jp>.

Underlying software: Copyright 1999-2004 The Apache Software Foundation, Copyright (c) 1996-1997 Cisco Systems, Inc., Copyright (c) Ian F. Darwin, 1987. Written by Ian F. Darwin.

LICENSE

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See http://www.perl.com/perl/misc/Artistic.html

Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 FILE::MMAGIC::XS (3) 2014-04-10

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.