337 lines
8.7 KiB
HTML
337 lines
8.7 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of File::MimeInfo</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>File::MimeInfo</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"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
File::MimeInfo - Determine file type from the file name
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
|
|
|
|
|
|
|
|
<PRE>
|
|
use File::MimeInfo;
|
|
my $mime_type = mimetype($file);
|
|
my $mime_type2 = mimetype('test.png');
|
|
|
|
</PRE>
|
|
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
|
|
|
|
This module can be used to determine the mime type of a file. It
|
|
tries to implement the freedesktop specification for a shared
|
|
<FONT SIZE="-1">MIME</FONT> database.
|
|
<P>
|
|
|
|
For this module shared-mime-info-spec 0.13 was used.
|
|
<P>
|
|
|
|
This package only uses the globs file. No real magic checking is
|
|
used. The File::MimeInfo::Magic package is provided for magic typing.
|
|
<P>
|
|
|
|
If you want to determine the mimetype of data in a memory buffer you should
|
|
use File::MimeInfo::Magic in combination with IO::Scalar.
|
|
<P>
|
|
|
|
This module loads the various data files when needed. If you want to
|
|
hash data earlier see the <TT>"rehash"</TT> methods below.
|
|
<A NAME="lbAE"> </A>
|
|
<H2>EXPORT</H2>
|
|
|
|
|
|
|
|
The method <TT>"mimetype"</TT> is exported by default.
|
|
The methods <TT>"inodetype"</TT>, <TT>"globs"</TT>, <TT>"extensions"</TT>, <TT>"describe"</TT>,
|
|
<TT>"mimetype_canon"</TT> and <TT>"mimetype_isa"</TT> can be exported on demand.
|
|
<A NAME="lbAF"> </A>
|
|
<H2>METHODS</H2>
|
|
|
|
|
|
|
|
<DL COMPACT>
|
|
<DT id="1">"new()"<DD>
|
|
|
|
|
|
|
|
|
|
Simple constructor to allow Object Oriented use of this module.
|
|
If you want to use this, include the package as <TT>"use File::MimeInfo ();"</TT>
|
|
to avoid importing sub <TT>"mimetype()"</TT>.
|
|
<DT id="2">"mimetype($file)"<DD>
|
|
|
|
|
|
|
|
|
|
Returns a mimetype string for <TT>$file</TT>, returns undef on failure.
|
|
|
|
|
|
<P>
|
|
|
|
|
|
This method bundles <TT>"inodetype"</TT> and <TT>"globs"</TT>.
|
|
|
|
|
|
<P>
|
|
|
|
|
|
If these methods are unsuccessful the file is read and the mimetype 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>"undef"</TT> is returned.
|
|
<DT id="3">"inodetype($file)"<DD>
|
|
|
|
|
|
|
|
|
|
Returns a mimetype in the 'inode' namespace or undef when the file is
|
|
actually a normal file.
|
|
<DT id="4">"globs($file)"<DD>
|
|
|
|
|
|
|
|
|
|
Returns a mimetype string for <TT>$file</TT> based on the filename and filename extensions.
|
|
Returns undef on failure. The file doesn't need to exist.
|
|
|
|
|
|
<P>
|
|
|
|
|
|
Behaviour in list context (wantarray) is unspecified and will change in future
|
|
releases.
|
|
<DT id="5">"default($file)"<DD>
|
|
|
|
|
|
|
|
|
|
This method decides whether a file is binary or plain text by looking at
|
|
the first few bytes in the file. Used to decide between ``text/plain'' and
|
|
``application/octet-stream'' if all other methods have failed.
|
|
|
|
|
|
<P>
|
|
|
|
|
|
The spec states that we should check for the ascii control chars and let
|
|
higher bit chars pass to allow utf8. We try to be more intelligent using
|
|
perl utf8 support.
|
|
<DT id="6">"extensions($mimetype)"<DD>
|
|
|
|
|
|
|
|
|
|
In list context, returns the list of filename extensions that map to the given mimetype.
|
|
In scalar context, returns the first extension that is found in the database
|
|
for this mimetype.
|
|
<DT id="7">"describe($mimetype, $lang)"<DD>
|
|
|
|
|
|
|
|
|
|
Returns a description of this mimetype as supplied by the mime info database.
|
|
You can specify a language with the optional parameter <TT>$lang</TT>, this should be
|
|
the two letter language code used in the xml files. Also you can set the global
|
|
variable <TT>$File::MimeInfo::LANG</TT> to specify a language.
|
|
|
|
|
|
<P>
|
|
|
|
|
|
This method returns undef when no xml file was found (i.e. the mimetype
|
|
doesn't exist in the database). It returns an empty string when the xml file doesn't
|
|
contain a description in the language you specified.
|
|
|
|
|
|
<P>
|
|
|
|
|
|
<I>Currently no real xml parsing is done, it trusts the xml files are nicely formatted.</I>
|
|
<DT id="8">"mimetype_canon($mimetype)"<DD>
|
|
|
|
|
|
|
|
|
|
Returns the canonical mimetype for a given mimetype.
|
|
Deprecated mimetypes are typically aliased to their canonical variants.
|
|
This method only checks aliases, doesn't check whether the mimetype
|
|
exists.
|
|
|
|
|
|
<P>
|
|
|
|
|
|
Use this method as a filter when you take a mimetype as input.
|
|
<DT id="9">"mimetype_isa($mimetype)"<DD>
|
|
|
|
|
|
|
|
|
|
|
|
<DT id="10">"mimetype_isa($mimetype, $mimetype)"<DD>
|
|
|
|
|
|
|
|
|
|
|
|
When give only one argument this method returns a list with mimetypes that are parent
|
|
classes for this mimetype.
|
|
|
|
|
|
<P>
|
|
|
|
|
|
When given two arguments returns true if the second mimetype is a parent class of
|
|
the first one.
|
|
|
|
|
|
<P>
|
|
|
|
|
|
This method checks the subclasses table and applies a few rules for implicit
|
|
subclasses.
|
|
<DT id="11">"rehash()"<DD>
|
|
|
|
|
|
|
|
|
|
Rehash the data files. Glob 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="12">"rehash_aliases()"<DD>
|
|
|
|
|
|
|
|
|
|
Rehashes the <I>mime/aliases</I> files.
|
|
<DT id="13">"rehash_subclasses()"<DD>
|
|
|
|
|
|
|
|
|
|
Rehashes the <I>mime/subclasses</I> files.
|
|
</DL>
|
|
<A NAME="lbAG"> </A>
|
|
<H2>DIAGNOSTICS</H2>
|
|
|
|
|
|
|
|
This module throws an exception when it can't find any data files, when it can't
|
|
open a data file it found for reading or when a subroutine doesn't get enough arguments.
|
|
In the first case you either don't have the freedesktop mime info database installed,
|
|
or your environment variables point to the wrong places,
|
|
in the second case you have the database installed, but it is broken
|
|
(the mime info database should logically be world readable).
|
|
<A NAME="lbAH"> </A>
|
|
<H2>TODO</H2>
|
|
|
|
|
|
|
|
Make an option for using some caching mechanism to reduce init time.
|
|
<P>
|
|
|
|
Make <TT>"describe()"</TT> use real xml parsing ?
|
|
<A NAME="lbAI"> </A>
|
|
<H2>LIMITATIONS</H2>
|
|
|
|
|
|
|
|
Perl versions prior to 5.8.0 do not have the ':utf8' <FONT SIZE="-1">IO</FONT> Layer, thus
|
|
for the default method and for reading the xml files
|
|
utf8 is not supported for these versions.
|
|
<P>
|
|
|
|
Since it is not possible to distinguish between encoding types (utf8, latin1, latin2 etc.)
|
|
in a straightforward manner only utf8 is supported (because the spec recommends this).
|
|
<P>
|
|
|
|
This module does not yet check extended attributes for a mimetype.
|
|
Patches for this are very welcome.
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>AUTHOR</H2>
|
|
|
|
|
|
|
|
Jaap Karssenberg <<A HREF="mailto:pardus@cpan.org">pardus@cpan.org</A>>
|
|
Maintained by Michiel Beijen <<A HREF="mailto:michiel.beijen@gmail.com">michiel.beijen@gmail.com</A>>
|
|
<A NAME="lbAK"> </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.
|
|
<A NAME="lbAL"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
|
|
|
|
File::BaseDir,
|
|
File::MimeInfo::Magic,
|
|
File::MimeInfo::Applications,
|
|
File::MimeInfo::Rox
|
|
<DL COMPACT>
|
|
<DT id="14">related <FONT SIZE="-1">CPAN</FONT> modules<DD>
|
|
|
|
|
|
File::MMagic
|
|
<DT id="15">freedesktop specifications used<DD>
|
|
|
|
|
|
<<A HREF="http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec">http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec</A>>,
|
|
<<A HREF="http://www.freedesktop.org/wiki/Specifications/basedir-spec">http://www.freedesktop.org/wiki/Specifications/basedir-spec</A>>,
|
|
<<A HREF="http://www.freedesktop.org/wiki/Specifications/desktop-entry-spec">http://www.freedesktop.org/wiki/Specifications/desktop-entry-spec</A>>
|
|
<DT id="16">freedesktop mime database<DD>
|
|
|
|
|
|
<<A HREF="http://www.freedesktop.org/wiki/Software/shared-mime-info">http://www.freedesktop.org/wiki/Software/shared-mime-info</A>>
|
|
<P>
|
|
</DL>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="17"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="18"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="19"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="20"><A HREF="#lbAE">EXPORT</A><DD>
|
|
<DT id="21"><A HREF="#lbAF">METHODS</A><DD>
|
|
<DT id="22"><A HREF="#lbAG">DIAGNOSTICS</A><DD>
|
|
<DT id="23"><A HREF="#lbAH">TODO</A><DD>
|
|
<DT id="24"><A HREF="#lbAI">LIMITATIONS</A><DD>
|
|
<DT id="25"><A HREF="#lbAJ">AUTHOR</A><DD>
|
|
<DT id="26"><A HREF="#lbAK">COPYRIGHT</A><DD>
|
|
<DT id="27"><A HREF="#lbAL">SEE ALSO</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>
|