1File::MimeInfo::Magic(3U)ser Contributed Perl DocumentatiFoinle::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 transparent to its
14 functions but adds support for the freedesktop magic file.
15
16 Magic data is hashed when you need it for the first time. If you want
17 to force hashing earlier use the rehash() function.
18
20 The method "mimetype" is exported by default. The methods "magic",
21 "inodetype", "globs" and "describe" can be exported on demand.
22
24 See also File::MimeInfo for methods that are inherited.
25
26 mimetype($file)
27 Returns a mime-type string for $file, returns undef on failure.
28
29 This method bundles inodetype(), globs() and magic().
30
31 Magic rules with an priority of 80 and higher are checked before
32 globs() is called, all other magic rules afterwards.
33
34 If this doesn't work the file is read and the mime-type defaults to
35 'text/plain' or to 'application/octet-stream' when the first ten
36 chars of the file match ascii control chars (white spaces
37 excluded). If the file doesn't exist or isn't readable "undef" is
38 returned.
39
40 If $file is an object reference only "magic" and the default method
41 are used. See below for details.
42
43 magic($file)
44 Returns a mime-type string for $file based on the magic rules,
45 returns undef on failure.
46
47 $file can be an object reference, in that case it is supposed to
48 have a seek() and a read() method. This allows you for example to
49 determine the mimetype of data in memory by using IO::Scalar.
50
51 Be aware that when using a filehandle or an "IO::" object you need
52 to set the ":utf8" binmode yourself if appropriate.
53
54 rehash()
55 Rehash the data files. Glob and magic information is preparsed when
56 this method is called.
57
58 If you want to by-pass the XDG basedir system you can specify your
59 database directories by setting @File::MimeInfo::DIRS. But normally
60 it is better to change the XDG basedir environment variables.
61
62 "default"
63 "describe"
64 "extensions"
65 "globs"
66 "inodetype"
67 These routines are imported from File::MimeInfo.
68
70 File::MimeInfo
71
73 Only word sizes of 1, 2 or 4 are supported. Any other word size is
74 ignored and will cause a warning.
75
77 Jaap Karssenberg <pardus@cpan.org> Maintained by Michiel Beijen
78 <mb@x14.nl>
79
81 Copyright (c) 2003, 2012 Jaap G Karssenberg. All rights reserved. This
82 program is free software; you can redistribute it and/or modify it
83 under the same terms as Perl itself.
84
85
86
87perl v5.38.2 2023-12-04 File::MimeInfo::Magic(3)