{"id":7461,"date":"2022-12-20T19:38:11","date_gmt":"2022-12-20T22:38:11","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/lwpmediatypes-man3\/"},"modified":"2022-12-20T19:38:11","modified_gmt":"2022-12-20T22:38:11","slug":"lwpmediatypes-man3","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/lwpmediatypes-man3\/","title":{"rendered":"LWP::MediaTypes (man3)"},"content":{"rendered":"<h1 align=\"center\">LWP::MediaTypes<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#COPYRIGHT\">COPYRIGHT<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">LWP::MediaTypes \u2212 guess media type for a file or a URL<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">use LWP::MediaTypes qw(guess_media_type); <br \/> $type = guess_media_type(&#8220;\/tmp\/foo.gif&#8221;);<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This module provides functions for handling media (also known as <small>MIME<\/small> ) types and encodings. The mapping from file extensions to media types is defined by the <i>media.types<\/i> file. If the <i>~\/.media.types<\/i> file exists it is used instead. For backwards compatibility we will also look for <i>~\/.mime.types<\/i>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The following functions are exported by default: <br \/> guess_media_type( $filename ) <br \/> guess_media_type( $uri ) <br \/> guess_media_type( $filename_or_object, $header_to_modify )<\/p>\n<p style=\"margin-left:17%;\">This function tries to guess media type and encoding for a file or objects that support the a &#8220;path&#8221; or &#8220;filename&#8221; method, eg, <small>URI<\/small> or File::Temp objects. When an object does not support either method, it will be stringified to determine the filename. It returns the content type, which is a string like &#8220;text\/html&#8221;. In array context it also returns any content encodings applied (in the order used to encode the file). You can pass a <small>URI<\/small> object reference, instead of the file name.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">If the type can not be deduced from looking at the file name, then <b>guess_media_type()<\/b> will let the &#8220;\u2212T&#8221; Perl operator take a look. If this works (and &#8220;\u2212T&#8221; returns a <small>TRUE<\/small> value) then we return <i>text\/plain<\/i> as the type, otherwise we return <i>application\/octet\u2212stream<\/i> as the type.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">The optional second argument should be a reference to a HTTP::Headers object or any object that implements the $obj\u2212>header method in a similar way. When it is present the values of the \u2019Content\u2212Type\u2019 and \u2019Content\u2212Encoding\u2019 will be set for this header.<\/p>\n<p style=\"margin-left:11%;\">media_suffix( $type, &#8230; )<\/p>\n<p style=\"margin-left:17%;\">This function will return all suffixes that can be used to denote the specified media type(s). Wildcard types can be used. In a scalar context it will return the first suffix found. Examples:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">@suffixes = media_suffix(&#8216;image\/*&#8217;, &#8216;audio\/basic&#8217;); <br \/> $suffix = media_suffix(&#8216;text\/html&#8217;);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The following functions are only exported by explicit request: <br \/> add_type( $type, @exts )<\/p>\n<p style=\"margin-left:17%;\">Associate a list of file extensions with the given media type. Example:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">add_type(&#8220;x\u2212world\/x\u2212vrml&#8221; => qw(wrl vrml));<\/p>\n<p style=\"margin-left:11%;\">add_encoding( $type, @ext )<\/p>\n<p style=\"margin-left:17%;\">Associate a list of file extensions with an encoding type. Example:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">add_encoding(&#8220;x\u2212gzip&#8221; => &#8220;gz&#8221;);<\/p>\n<p style=\"margin-left:11%;\">read_media_types( @files )<\/p>\n<p style=\"margin-left:17%;\">Parse media types files and add the type mappings found there. Example:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">read_media_types(&#8220;conf\/mime.types&#8221;);<\/p>\n<h2>COPYRIGHT <a name=\"COPYRIGHT\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Copyright 1995\u22121999 Gisle Aas.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">This library is free software; you can redistribute it and\/or modify it under the same terms as Perl itself.<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  LWP::MediaTypes \u2212 guess media type for a file or a URL <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3773,3007],"class_list":["post-7461","post","type-post","status-publish","format-standard","hentry","category-sin-categoria","tag-lwpmediatypes","tag-man3"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/7461","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=7461"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/7461\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=7461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=7461"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=7461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}