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

TODO

46           * Add additional magic match criteria
47

BUGS

49       None known.
50
51   NOTES
52       Some magic definitions in the mime-magic file used in the creation of
53       this module vary from those in other apps (eg image/x-png not
54       image/png).
55

SEE ALSO

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

ACKNOWLEDGMENTS

75       File::Type is built from a mime-magic file from cleancode.org. The
76       original can be found at
77       <http://cleancode.org/cgi-bin/viewcvs.cgi/email/mime-magic.mime?rev=1.1.1.1>.
78

AUTHOR

80       Paul Mison <pmison@fotango.com>
81
83       Copyright 2003-2004 Fotango Ltd.
84

LICENSE

86       Licensed under the same terms as Perl itself.
87
88
89
90perl v5.28.1                      2019-02-02                     File::Type(3)
Impressum