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

NAME

6       File::Type - determine file type using magic
7

SYNOPSIS

9           my $ft = File::Type->new();
10
11           # read in data from file to $data, then
12           my $type_from_data = $ft->checktype_contents($data);
13
14           # alternatively, check file from disk
15           my $type_from_file = $ft->checktype_filename($file);
16
17           # convenient method for checking either a file or data
18           my $type_1 = $ft->mime_type($file);
19           my $type_2 = $ft->mime_type($data);
20

DESCRIPTION

22       File::Type uses magic numbers (typically at the start of a file) to
23       determine the MIME type of that file.
24
25       File::Type can use either a filename, or file contents, to determine
26       the type of a file.
27

METHODS

29       new
30
31       Returns a new File::Type object.
32
33       mime_type($argument)
34
35       Takes either data or a filename, determines what it is, and passes the
36       argument through to the relevant method below. If the argument is a
37       directory, returns undef.
38
39       checktype_filename($filename)
40
41       Opens $filename (if possible; if not, returns undef) and returns the
42       MIME type of the file.
43
44       checktype_contents($data)
45
46       Matches $data against the magic database criteria and returns the MIME
47       type of the file.
48

TODO

50           * Add additional magic match criteria
51

BUGS

53       None known.
54
55       NOTES
56
57       Some magic definitions in the mime-magic file used in the creation of
58       this module vary from those in other apps (eg image/x-png not
59       image/png).
60

SEE ALSO

62       File::MMagic and File::MimeInfo perform the same job, but have a number
63       of problems that led to the creation of this module.
64
65       File::MMagic inlines a copy of the magic database, and uses a DATA
66       filehandle, which causes problems when running under mod_perl.
67
68       File::MimeInfo uses an external magic file, and relies on file exten‐
69       sions rather than magic to determine the mime type.
70
71       As a result, File::Type uses a seperate module and script to create the
72       code at the core of this module, which means that there is no need to
73       include a magic database at all, and that it is safe to run under
74       mod_perl.
75
76       File::Type::Builder, which generates the code at the heart of this mod‐
77       ule.
78

ACKNOWLEDGMENTS

80       File::Type is built from a mime-magic file from cleancode.org. The
81       original can be found at <http://clean
82       code.org/cgi-bin/viewcvs.cgi/email/mime-magic.mime?rev=1.1.1.1>.
83

AUTHOR

85       Paul Mison <pmison@fotango.com>
86
88       Copyright 2003-2004 Fotango Ltd.
89

LICENSE

91       Licensed under the same terms as Perl itself.
92
93
94
95perl v5.8.8                       2007-04-17                     File::Type(3)
Impressum