man-pages/man3/File::MimeInfo::Magic.3pm.html
2021-03-31 01:06:50 +01:00

208 lines
4.5 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of File::MimeInfo::Magic</TITLE>
</HEAD><BODY>
<H1>File::MimeInfo::Magic</H1>
Section: User Contributed Perl Documentation (3pm)<BR>Updated: 2018-08-06<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
File::MimeInfo::Magic - Determine file type with magic
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
use File::MimeInfo::Magic;
my $mime_type = mimetype($file);
</PRE>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
This module inherits from File::MimeInfo, it is transparent
to its functions but adds support for the freedesktop magic file.
<P>
Magic data is hashed when you need it for the first time.
If you want to force hashing earlier use the <TT>&quot;rehash()&quot;</TT> function.
<A NAME="lbAE">&nbsp;</A>
<H2>EXPORT</H2>
The method <TT>&quot;mimetype&quot;</TT> is exported by default. The methods <TT>&quot;magic&quot;</TT>,
<TT>&quot;inodetype&quot;</TT>, <TT>&quot;globs&quot;</TT> and <TT>&quot;describe&quot;</TT> can be exported on demand.
<A NAME="lbAF">&nbsp;</A>
<H2>METHODS</H2>
See also File::MimeInfo for methods that are inherited.
<DL COMPACT>
<DT id="1">&quot;mimetype($file)&quot;<DD>
Returns a mime-type string for <TT>$file</TT>, returns undef on failure.
<P>
This method bundles <TT>&quot;inodetype()&quot;</TT>, <TT>&quot;globs()&quot;</TT> and <TT>&quot;magic()&quot;</TT>.
<P>
Magic rules with an priority of 80 and higher are checked before
<TT>&quot;globs()&quot;</TT> is called, all other magic rules afterwards.
<P>
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 <TT>&quot;undef&quot;</TT> is returned.
<P>
If <TT>$file</TT> is an object reference only <TT>&quot;magic&quot;</TT> and the default method
are used. See below for details.
<DT id="2">&quot;magic($file)&quot;<DD>
Returns a mime-type string for <TT>$file</TT> based on the magic rules,
returns undef on failure.
<P>
<TT>$file</TT> can be an object reference, in that case it is supposed to have a
<TT>&quot;seek()&quot;</TT> and a <TT>&quot;read()&quot;</TT> method. This allows you for example to determine
the mimetype of data in memory by using IO::Scalar.
<P>
Be aware that when using a filehandle or an <TT>&quot;IO::&quot;</TT> object you need to set
the <TT>&quot;:utf8&quot;</TT> binmode yourself if appropriate.
<DT id="3">&quot;rehash()&quot;<DD>
Rehash the data files. Glob and magic
information is preparsed when this method is called.
<P>
If you want to by-pass the <FONT SIZE="-1">XDG</FONT> basedir system you can specify your database
directories by setting <TT>@File::MimeInfo::DIRS</TT>. But normally it is better to
change the <FONT SIZE="-1">XDG</FONT> basedir environment variables.
<DT id="4">&quot;default&quot;<DD>
<DT id="5">&quot;describe&quot;<DD>
<DT id="6">&quot;extensions&quot;<DD>
<DT id="7">&quot;globs&quot;<DD>
<DT id="8">&quot;inodetype&quot;<DD>
These routines are imported from File::MimeInfo.
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>SEE ALSO</H2>
File::MimeInfo
<A NAME="lbAH">&nbsp;</A>
<H2>LIMITATIONS</H2>
Only word sizes of 1, 2 or 4 are supported. Any other word size is ignored
and will cause a warning.
<A NAME="lbAI">&nbsp;</A>
<H2>AUTHOR</H2>
Jaap Karssenberg &lt;<A HREF="mailto:pardus@cpan.org">pardus@cpan.org</A>&gt;
Maintained by Michiel Beijen &lt;<A HREF="mailto:michiel.beijen@gmail.com">michiel.beijen@gmail.com</A>&gt;
<A NAME="lbAJ">&nbsp;</A>
<H2>COPYRIGHT</H2>
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.
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="9"><A HREF="#lbAB">NAME</A><DD>
<DT id="10"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="11"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="12"><A HREF="#lbAE">EXPORT</A><DD>
<DT id="13"><A HREF="#lbAF">METHODS</A><DD>
<DT id="14"><A HREF="#lbAG">SEE ALSO</A><DD>
<DT id="15"><A HREF="#lbAH">LIMITATIONS</A><DD>
<DT id="16"><A HREF="#lbAI">AUTHOR</A><DD>
<DT id="17"><A HREF="#lbAJ">COPYRIGHT</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:43 GMT, March 31, 2021
</BODY>
</HTML>