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
28       :compat 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
41       suggestions/recommendations about the interface or anything else, now
42       is your chance to send them!
43

METHODS

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

PERFORMANCE

96       This is on my laptop (MacBook, Core 2 Duo/ Mac OS X 10.4.3), tested
97       against File::MMagic::XS 0.09003
98
99                 Rate  perl    xs
100         perl   513/s    --  -96%
101         xs   12048/s 2249%    --
102

SEE ALSO

104       File::MMagic
105

AUTHOR

107       Copyright 2005-2007 Daisuke Maki <daisuke@endeworks.jp>.
108
109       Underlying software: Copyright 1999-2004 The Apache Software
110       Foundation, Copyright (c) 1996-1997 Cisco Systems, Inc., Copyright (c)
111       Ian F. Darwin, 1987. Written by Ian F. Darwin.
112

LICENSE

114       This program is free software; you can redistribute it and/or modify it
115       under the same terms as Perl itself.
116
117       See http://www.perl.com/perl/misc/Artistic.html
118
119
120
121perl v5.32.1                      2021-01-27               File::MMagic::XS(3)
Impressum