File::M...o::Magic(3)
π NAME π
File::MimeInfo::Magic β determine file type with magic. β¨
okay bestie, this is the File::M...o::Magic(3) page β User Contributed Perl Documentation β and it's literally all about File::MimeInfo::Magic. π
β¨ SYNOPSIS β¨
use File::MimeInfo::Magic;
my $mime_type = mimetype($file);
π¦ DESCRIPTION π¦
This module inherits from File::MimeInfo. It's transparent to its functions but adds support for the freedesktop magic file. π
Magic data is hashed when you need it for the first time. If you want to force hashing earlier, use the rehash() function. π₯
π EXPORT π
The method mimetype is exported by default. The methods magic, inodetype, globs and describe can be exported on demand. periodt. π
π METHODS π
See also File::MimeInfo for methods that are inherited. π«Ά
π mimetype($file)
Returns a mime-type string for $file, returns undef on failure. π
This method bundles inodetype(), globs() and magic(). The way that it works: magic rules with a priority of 80 and higher are checked before globs() is called, all other magic rules afterwards. β
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, undef is returned. π
If $file is an object reference, only magic and the default method are used. See below for details. π
π₯ magic($file)
Returns a mime-type string for $file based on the magic rules, returns undef on failure. πΈ
$file can be an object reference; in that case it is supposed to have a seek() and a read() method. This allows you, for example, to determine the mimetype of data in memory by using IO::Scalar. π§
Be aware that when using a filehandle or an IO:: object you need to set the :utf8 binmode yourself if appropriate. π
π rehash()
Rehash the data files. Glob and magic information is preparsed when this method is called. π«
If you want to by-pass the XDG basedir system you can specify your database directories by setting @File::MimeInfo::DIRS. But normally it is better to change the XDG basedir environment variables. π
π«Ά "default", "describe", "extensions", "globs", "inodetype"
These routines are imported from File::MimeInfo. π
π SEE ALSO π
File::MimeInfo
π LIMITATIONS π
Only word sizes of1,2or4are supported. Any other word size is ignored and will cause a warning. β οΈ
π AUTHOR π
Jaap Karssenberg <pardus@cpan.org> β maintained by Michiel Beijen <mb@x14.nl>. π«‘
π 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. π
mwah π β that's a wrap, bestie. This page is signed off with perl v5.42.0, dated 2024-04-26, and filed under File::M...o::Magic(3). πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-File-MimeInfo 0.350.0-bp160.1.11 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms