1MimeInfo::Magic(3) User Contributed Perl Documentation MimeInfo::Magic(3)
2
3
4
6 File::MimeInfo::Magic - Determine file type with magic
7
9 use File::MimeInfo::Magic;
10 my $mime_type = mimetype($file);
11
13 This module inherits from File::MimeInfo, it is transparant to its
14 functions but adds support for the freedesktop magic file.
15
17 The method "mimetype" is exported by default. The methods "magic",
18 "inodetype", "globs" and "describe" can be exported on demand.
19
21 See also File::MimeInfo for methods that are inherited.
22
23 "mimetype($file)"
24 Returns a mime-type string for $file, returns undef on failure.
25
26 This method bundles "inodetype()", "globs()" and "magic()".
27
28 Magic rules with an priority of 80 and higher are checked before
29 "globs()" is called, all other magic rules afterwards.
30
31 If this doesn't work the file is read and the mime-type defaults to
32 'text/plain' or to 'application/octet-stream' when the first ten
33 chars of the file match ascii control chars (white spaces
34 excluded). If the file doesn't exist or isn't readable "undef" is
35 returned.
36
37 If $file is an object reference only "magic" and the default method
38 are used.
39
40 "magic($file)"
41 Returns a mime-type string for $file based on the magic rules,
42 returns undef on failure.
43
44 $file can be an object reference, in that case it is supposed to
45 have a "seek()" and a "read()" method. This allows you for example
46 to determine the mimetype of data in memory by using IO::Scalar.
47
48 "rehash()"
49 Rehash the data files. Glob and magic information is preparsed when
50 this method is called.
51
52 If you want to by-pass the XDG basedir system you can specify your
53 database directories by setting @File::MimeInfo::DIRS. But normally
54 it is better to change the XDG basedir environment variables.
55
57 File::MimeInfo
58
60 Please mail the author when you encounter any bugs.
61
62 Most likely to cause bugs is the fact that I partially used line based
63 parsing while the source data is binary and can contain newlines on
64 strange places. I tested with the 0.11 version of the database and
65 found no problems, but I can think of configurations that can cause
66 problems.
67
69 Jaap Karssenberg ⎪⎪ Pardus [Larus] <pardus@cpan.org>
70
71 Copyright (c) 2003 Jaap G Karssenberg. All rights reserved. This pro‐
72 gram is free software; you can redistribute it and/or modify it under
73 the same terms as Perl itself.
74
75
76
77perl v5.8.8 2005-10-03 MimeInfo::Magic(3)