Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

file::mmagic::xs(3pm) [debian man page]

File::MMagic::XS(3pm)					User Contributed Perl Documentation				     File::MMagic::XS(3pm)

NAME
File::MMagic::XS - Guess File Type With XS (a la mod_mime_magic) 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, $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 perl v5.14.2 2010-05-18 File::MMagic::XS(3pm)

Check Out this Related Man Page

MMagic(3pm)						User Contributed Perl Documentation					       MMagic(3pm)

NAME
File::MMagic - Guess file type SYNOPSIS
use File::MMagic; use FileHandle; $mm = new File::MMagic; # use internal magic file # $mm = File::MMagic->new('/etc/magic'); # use external magic file # $mm = File::MMagic->new('/usr/share/etc/magic'); # if you use Debian $res = $mm->checktype_filename("/somewhere/unknown/file"); $fh = new FileHandle "< /somewhere/unknown/file2"; $res = $mm->checktype_filehandle($fh); $fh->read($data, 0x8564); $res = $mm->checktype_contents($data); ABSTRACT
This perl library uses perl5 objects to guess file type from filename and/or filehandle. DESCRIPTION
checktype_filename(), checktype_filehandle() and checktype_contents returns string contains file type with MIME mediatype format. METHODS
File::MMagic->new() File::MMagic->new( $filename ) Initializes the module. If no filename is given, the magic numbers stored in File::MMagic are used. $mm->addSpecials If a filetype cannot be determined by magic numbers, extra checks are done based on extra regular expressions which can be defined here. The first argument should be the filetype, the remaining arguments should be one or more regular expressions. By default, checks are done for message/news, message/rfc822, text/html, text/x-roff. $mm->removeSpecials Removes special regular expressions. Specify one or more filetypes. If no filetypes are specified, all special regexps are removed. Returns a hash containing the removed entries. $mm->addFileExts If a filetype cannot be determined by magic numbers, extra checks can be done based on the file extension (actually, a regexp). Two arguments should be geiven: the filename pattern and the corresponding filetype. By default, checks are done for application/x-compress, application/x-bzip2, application/x-gzip, text/html, text/plain $mm->removeFileExts Remove filename pattern checks. Specify one or more patterns. If no pattern is specified, all are removed. Returns a hash containing the removed entries. $mm->addMagicEntry Add a new magic entry in the object. The format is same as magic(5) file. Ex. # Add a entry $mm->addMagicEntry("0 string abc text/abc"); # Add a entry with a sub entry $mm->addMagicEntry("0 string def "); $mm->addMagicEntry(">10 string ghi text/ghi"); $mm->readMagicHandle $mm->checktype_filename $mm->checktype_magic $mm->checktype_contents COPYRIGHT
This program is originated from file.kulp that is a production of The Unix Reconstruction Projct. <http://language.perl.com/ppt/index.html> Copyright (c) 1999 NOKUBI Takatsugu <knok@daionet.gr.jp>. There is no warranty for the program. This product includes software developed by the Apache Group for use in the Apache HTTP server project (http://www.apache.org/). License for the program is followed the original software. The license is below. This program is free and open software. You may use, copy, modify, distribute and sell this program (and any modified variants) in any way you wish, provided you do not restrict others to do the same, except for the following consideration. I read some of Ian F. Darwin's BSD C implementation, to try to determine how some of this was done since the specification is a little vague. I don't believe that this perl version could be construed as an "altered version", but I did grab the tokens for identifying the hard-coded file types in names.h and copied some of the man page. Here's his notice: * Copyright (c) Ian F. Darwin, 1987. * Written by Ian F. Darwin. * * This software is not subject to any license of the American Telephone * and Telegraph Company or of the Regents of the University of California. * * Permission is granted to anyone to use this software for any purpose on * any computer system, and to alter it and redistribute it freely, subject * to the following restrictions: * * 1. The author is not responsible for the consequences of use of this * software, no matter how awful, even if they arise from flaws in it. * * 2. The origin of this software must not be misrepresented, either by * explicit claim or by omission. Since few users ever read sources, * credits must appear in the documentation. * * 3. Altered versions must be plainly marked as such, and must not be * misrepresented as being the original software. Since few users * ever read sources, credits must appear in the documentation. * * 4. This notice may not be removed or altered. The following is the Apache License. This program contains the magic file that derived from the Apache HTTP Server. * Copyright (c) 1995-1999 The Apache Group. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. All advertising materials mentioning features or use of this * software must display the following acknowledgment: * "This product includes software developed by the Apache Group * for use in the Apache HTTP server project (http://www.apache.org/)." * * 4. The names "Apache Server" and "Apache Group" must not be used to * endorse or promote products derived from this software without * prior written permission. For written permission, please contact * apache@apache.org. * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * 6. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by the Apache Group * for use in the Apache HTTP server project (http://www.apache.org/)." * * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. POD ERRORS
Hey! The above document had some coding errors, which are explained below: Around line 200: You forgot a '=back' before '=head1' perl v5.14.2 2012-11-28 MMagic(3pm)
Man Page