1File::MMagic::XS(3)   User Contributed Perl Documentation  File::MMagic::XS(3)
2
3
4

NAME

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

SYNOPSIS

9         use File::MMagic::XS;
10
11         my $m = File::MMagic::XS->new();
12            $m = File::MMagic::XS->new('/etc/magic'); # use external magic file
13
14         my $mime = $m->get_mime($file);
15
16         # use File::MMagic compatible interface
17         use File::MMagic::XS qw(:compat);
18
19         my $m = File::MMagic::XS->new();
20         $m->checktype_filename($file);
21

DESCRIPTION

23       This is a port of Apache2 mod_mime_magic.c in Perl, written in XS with
24       the aim of being efficient and fast especially for applications that
25       need to be run for an extended amount of time.
26
27       There is a compatibility layer for File::MMagic. you can specify :com‐
28       pat when importing the module
29
30          use File::MMagic::XS qw(:compat);
31
32       And then the following methods are going to be available from
33       File::MMagic::XS:
34
35          checktype_filename
36          checktype_filehandle
37          checktype_contents
38          addMagicEntry
39
40       Currently this software is in beta. If you have suggestions/recommenda‐
41       tions about the interface or anything else, now is your chance to send
42       them!
43

METHODS

45       new(%args)
46
47       Creates a new File::MMagic::XS object.
48
49       If you specify the "file" argument, then File::MMagic::XS will load
50       magic definitions from the specified file. If unspecified, it will use
51       the magic file that will be installed under File/MMagic/ directory.
52
53       parse_magic_file($file)
54
55       Read and parse a magic file, as used by Apache2.
56
57       get_mime($file)
58
59       Inspects the file specified by $file and returns a MIME type if possi‐
60       ble.  If no matching MIME type is found, then undef is returned.
61
62       fsmagic($file)
63
64       Inspects a file and returns a MIME type using inode information only.
65       The contents of the file is not inspected.
66
67       fhmagic($fh)
68
69       Inspects a file handle and returns a mime string by reading the con‐
70       tents of the file handle.
71
72       ascmagic($file)
73
74       Inspects a piece of data (assuming it's not binary data), and attempts
75       to determine the file type.
76
77       bufmagic($scalar)
78
79       Inspects a scalar buffer, and attempts to determine the file type
80
81       add_magic($magic_line)
82
83       Adds a new magic entry to the object. The format of $magic_line is the
84       same as magic(5) file. This allows you to add custom magic entries at
85       run time
86
87       add_file_ext($ext, $mime)
88
89       Adds a new file extension to MIME mapping. This is used as a fallback
90       method to determining MIME types.
91
92         my $magic = File::MMagic::XS->new;
93         $magic->add_file_ext('t', 'text/perl-test');
94         my $mime  = $magic->get_mime('t/01-sanity.t');
95
96       This will make get_mime() return 'text/perl-test'.
97
98       error()
99
100       Returns the last error string.
101

PERFORMANCE

103                 Rate   perl     xs
104         perl  89.1/s     --  -100%
105         xs   24390/s 27283%     --
106
107       Hey, I told you it's fast...
108

SEE ALSO

110       File::MMagic
111

AUTHOR

113       Copyright 2005-2007 Daisuke Maki <daisuke@endeworks.jp>.
114
115       Underlying software: Copyright 1999-2004 The Apache Software Founda‐
116       tion, Copyright (c) 1996-1997 Cisco Systems, Inc., Copyright (c) Ian F.
117       Darwin, 1987. Written by Ian F. Darwin.
118

LICENSE

120       This program is free software; you can redistribute it and/or modify it
121       under the same terms as Perl itself.
122
123       See http://www.perl.com/perl/misc/Artistic.html
124
125
126
127perl v5.8.8                       2007-07-08               File::MMagic::XS(3)
Impressum