.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "File::MimeInfo::Magic 3pm" .TH File::MimeInfo::Magic 3pm "2023-12-06" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" File::MimeInfo::Magic \- Determine file type with magic .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& use File::MimeInfo::Magic; \& my $mime_type = mimetype($file); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module inherits from File::MimeInfo, it is transparent to its functions but adds support for the freedesktop magic file. .PP Magic data is hashed when you need it for the first time. If you want to force hashing earlier use the \f(CW\*(C`rehash()\*(C'\fR function. .SH "EXPORT" .IX Header "EXPORT" The method \f(CW\*(C`mimetype\*(C'\fR is exported by default. The methods \f(CW\*(C`magic\*(C'\fR, \&\f(CW\*(C`inodetype\*(C'\fR, \f(CW\*(C`globs\*(C'\fR and \f(CW\*(C`describe\*(C'\fR can be exported on demand. .SH "METHODS" .IX Header "METHODS" See also File::MimeInfo for methods that are inherited. .ie n .IP """mimetype($file)""" 4 .el .IP "\f(CWmimetype($file)\fR" 4 .IX Item "mimetype($file)" Returns a mime-type string for \f(CW$file\fR, returns undef on failure. .Sp This method bundles \f(CW\*(C`inodetype()\*(C'\fR, \f(CW\*(C`globs()\*(C'\fR and \f(CW\*(C`magic()\*(C'\fR. .Sp Magic rules with an priority of 80 and higher are checked before \&\f(CW\*(C`globs()\*(C'\fR is called, all other magic rules afterwards. .Sp If this doesn't work the file is read and the mime-type defaults to 'text/plain' or to 'application/octet\-stream' when the first ten chars of the file match ascii control chars (white spaces excluded). If the file doesn't exist or isn't readable \f(CW\*(C`undef\*(C'\fR is returned. .Sp If \f(CW$file\fR is an object reference only \f(CW\*(C`magic\*(C'\fR and the default method are used. See below for details. .ie n .IP """magic($file)""" 4 .el .IP "\f(CWmagic($file)\fR" 4 .IX Item "magic($file)" Returns a mime-type string for \f(CW$file\fR based on the magic rules, returns undef on failure. .Sp \&\f(CW$file\fR can be an object reference, in that case it is supposed to have a \&\f(CW\*(C`seek()\*(C'\fR and a \f(CW\*(C`read()\*(C'\fR method. This allows you for example to determine the mimetype of data in memory by using IO::Scalar. .Sp Be aware that when using a filehandle or an \f(CW\*(C`IO::\*(C'\fR object you need to set the \f(CW\*(C`:utf8\*(C'\fR binmode yourself if appropriate. .ie n .IP """rehash()""" 4 .el .IP "\f(CWrehash()\fR" 4 .IX Item "rehash()" Rehash the data files. Glob and magic information is preparsed when this method is called. .Sp If you want to by-pass the \s-1XDG\s0 basedir system you can specify your database directories by setting \f(CW@File::MimeInfo::DIRS\fR. But normally it is better to change the \s-1XDG\s0 basedir environment variables. .ie n .IP """default""" 4 .el .IP "\f(CWdefault\fR" 4 .IX Item "default" .PD 0 .ie n .IP """describe""" 4 .el .IP "\f(CWdescribe\fR" 4 .IX Item "describe" .ie n .IP """extensions""" 4 .el .IP "\f(CWextensions\fR" 4 .IX Item "extensions" .ie n .IP """globs""" 4 .el .IP "\f(CWglobs\fR" 4 .IX Item "globs" .ie n .IP """inodetype""" 4 .el .IP "\f(CWinodetype\fR" 4 .IX Item "inodetype" .PD These routines are imported from File::MimeInfo. .SH "SEE ALSO" .IX Header "SEE ALSO" File::MimeInfo .SH "LIMITATIONS" .IX Header "LIMITATIONS" Only word sizes of 1, 2 or 4 are supported. Any other word size is ignored and will cause a warning. .SH "AUTHOR" .IX Header "AUTHOR" Jaap Karssenberg Maintained by Michiel Beijen .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright (c) 2003, 2012 Jaap G Karssenberg. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.