How to use the mime.types function in mime

To help you get started, we’ve selected a few mime examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Munter / expush / lib / expush.js View on Github external
}), function (foundAsset, cb) {
            if (!foundAsset.isLoaded || foundAsset === asset || !foundAsset.url) {
                return setImmediate(cb);
            }

            var headers = {
//                    'cache-control': 'max-age=0, must-revalidate',
                    'content-type': mime.types[foundAsset.extension.substr(1) || 'application/octet-stream'],
                    etag: '"' + foundAsset.md5Hex + '"'
                },
                path = foundAsset.url.replace(assetGraph.root, '/'),
                stream = res.push(path, headers),
                hasEnded = false;

            stream
                .on('error', function (err) {
                    err.message = path + ': push stream emitted error - ' + err.message;
                    console.error(err);
                    if (!hasEnded) {
                        hasEnded = true;
                        cb();
                    }
                })
                .on('acknowledge', function () {
github mikeal / response / index.js View on Github external
}
}

function response (view, opts) {
  return new Response(view, opts)
}

var typemap = {};
typemap['txt'] = function(view) {
  return (typeof view != 'string') ? view.toString() : view
}
typemap['json'] = function(view) {
  return JSON.stringify(view)
}

Object.keys(mime.types).forEach(function (mimeName) {

    // set mime convenience methods
  function _response (view, opts) {
    view = (typemap[mimeName]) ? typemap[mimeName](view) : view
    var r = response(view, opts)
    r.setHeader('content-type', mime.types[mimeName])
    return r
  }
  response[mimeName] = _response
  // set mime methods
  Response.prototype[mimeName] = function (view) {
    view = (typemap[mimeName]) ? typemap[mimeName](view) : view
    var self = this
    self.setHeader('content-type', mime.types[mimeName])
    process.nextTick(function () {
        self.end(view)
github jshttp / compressible / test / benchmarks.js View on Github external
function getRandomType () {
  var type = mime.types[keys[Math.floor(Math.random() * keys.length)]]
  return type + mime.charsets.lookup(type)
}
github DoubleSpout / ifile / lib / ifile.js View on Github external
var add_mime = function(){

	var len = Object.keys(mime.types).length;
	var types = mime.types;
	var types_keys = Object.keys(mime.types);
	var mime_name_array = [];
	var mime_type_array = [];
	for(var i=0;i
github DoubleSpout / ifile / lib / ifile.js View on Github external
var add_mime = function(){

	var len = Object.keys(mime.types).length;
	var types = mime.types;
	var types_keys = Object.keys(mime.types);
	var mime_name_array = [];
	var mime_type_array = [];
	for(var i=0;i
github tjanczuk / iisnode / src / iisnode / node-inspector-0.7.3 / node_modules / node-inspector / node_modules / compressible / bench.js View on Github external
var assert = require('assert')
  , Benchmark = require('benchmark')
  , suite = new Benchmark.Suite
  , mime = require('mime')
  , keys = Object.keys(mime.types)
  , compressible = require('./index.js')
  , benchmarks = require('beautify-benchmark')

function getRandomType () {
  var type = mime.types[keys[Math.floor(Math.random() * keys.length)]]
  return type + mime.charsets.lookup(type)
}

function legacy (type) {
  if (!type || typeof type !== "string") return false
  var spec = compressible.specs[type.split(';')]
  return spec ? spec.compressible : compressible.regex.test(type)
}

function previous (type) {
  if (!type || typeof type !== "string") return false
github Munter / expush / lib / expush.js View on Github external
function sendAsset(asset, req, res, next) {
    var contentType = mime.types[asset.extension.substr(1) || 'application/octet-stream'],
        etag = '"' + asset.md5Hex + '"',
        ifNoneMatchHeaderValue = req.headers['if-none-match'];

    if (ifNoneMatchHeaderValue && ifNoneMatchHeaderValue.indexOf(etag) !== -1) {
        return res.send(304);
    }

    res.setHeader('Content-Type', contentType);
    res.setHeader('ETag', etag);

    if (req.isSpdy && contentType === 'text/html') {
        res.write(asset.rawSrc);

        async.each(assetGraph.collectAssetsPreOrder(asset, {
            type: query.not(['HtmlAnchor', 'JavaScriptSourceMappingUrl', 'JavaScriptSourceUrl']),
            to: {
github mikeal / response / index.js View on Github external
function _response (view, opts) {
    view = (typemap[mimeName]) ? typemap[mimeName](view) : view
    var r = response(view, opts)
    r.setHeader('content-type', mime.types[mimeName])
    return r
  }
  response[mimeName] = _response
github tjanczuk / iisnode / src / iisnode / node-inspector-0.7.3 / node_modules / node-inspector / node_modules / compressible / bench.js View on Github external
function getRandomType () {
  var type = mime.types[keys[Math.floor(Math.random() * keys.length)]]
  return type + mime.charsets.lookup(type)
}