mime类型模块 - 编程技术参考——模具行业从业者必备知识手册
-
<h2>mime</h2>
<p>Comprehensive MIME type mapping API based on mime-db module.</p>
<h3>Install</h3>
<p>Install with <a href="http://github.com/isaacs/npm">npm</a>:</p>
<p> npm install mime</p>
<h3>Contributing / Testing</h3>
<p> npm run test</p>
<h3>Command Line</h3>
<p> mime [path_string]</p>
<p>E.g.</p>
<blockquote>
<p>mime scripts/jquery.js</p>
</blockquote>
<p> application/javascript</p><h3>API - Queries</h3>
<h4>mime.lookup(path)</h4>
<p>Get the mime type associated with a file, if no mime type is found <code>application/octet-stream</code> is returned. Performs a case-insensitive lookup using the extension in <code>path</code> (the substring after the last '/' or '.'). E.g.</p><pre><code>
var mime = require('mime');mime.lookup('/path/to/file.txt'); // => 'text/plain'
mime.lookup('file.txt'); // => 'text/plain'
mime.lookup('.TXT'); // => 'text/plain'
mime.lookup('htm'); // => 'text/html'
</code></pre><h4>mime.default_type</h4>
<p>Sets the mime type returned when <code>mime.lookup</code> fails to find the extension searched for. (Default is <code>application/octet-stream</code>.)</p><h4>mime.extension(type)</h4>
<p>Get the default extension for <code>type</code></p><pre><code>
mime.extension('text/html'); // => 'html'
mime.extension('application/octet-stream'); // => 'bin'
</code></pre><h4>mime.charsets.lookup()</h4>
<p>Map mime-type to charset</p>
<pre><code>
mime.charsets.lookup('text/plain'); // => 'UTF-8'
</code></pre><p>(The logic for charset lookups is pretty rudimentary. Feel free to suggest improvements.)</p>
<h3>API - Defining Custom Types</h3>
<p>Custom type mappings can be added on a per-project basis via the following APIs.</p>
<h4>mime.define()</h4>
<p>Add custom mime/extension mappings</p>
<pre><code>
mime.define({
'text/x-some-format': ['x-sf', 'x-sft', 'x-sfml'],
'application/x-my-type': ['x-mt', 'x-mtt'],
// etc ...
});mime.lookup('x-sft'); // => 'text/x-some-format'
</code></pre><p>The first entry in the extensions array is returned by <code>mime.extension()</code>. E.g.</p>
<pre><code>
mime.extension('text/x-some-format'); // => 'x-sf'
</code></pre><h4>mime.load(filepath)</h4>
<p>Load mappings from an Apache ".types" format file</p>
<pre><code>
mime.load('./my_project.types');
</code></pre>
<p>The .types file format is simple - See the <code>types</code> dir for examples.</p><hr>
<p>本文由模极社发布</p>
<hr>
<p>!<a href="upload://im5w4bbZS7qEfHo32U8caxAUX72.svg">mime类型模块 - 编程技术参考</a></p><hr>
<h4>
你可能还感兴趣</h4>
<ul>
<li><a href="/t/4521/4521">@intlify/message-compiler</a></li>
<li><a href="/t/2808/2808">定模座板功能说明与设计选型指南</a></li>
<li><a href="/t/898/898">侧浇口适合什么产品?</a></li>
</ul><hr>
<p><strong>相关推荐:</strong></p>
<ul>
<li><a href="https://www.mj7.cn/t/4836-4836">北京模具产业 — 科技研发驱动型模具基地</a></li>
<li><a href="https://www.mj7.cn/t/4835-4835">上海模具产业 — 高端精密模具研发中心</a></li>
<li><a href="https://www.mj7.cn/t/4834-4834">产业集群与模具产业发展的关系</a></li>
</ul><hr>
<p>你们厂里是怎么处理的?来评论区聊聊。</p>