/* automatically generated by JSCoverage - do not edit */
if (typeof _$jscoverage === 'undefined') _$jscoverage = {};
if (! _$jscoverage['middleware/multipart.js']) {
  _$jscoverage['middleware/multipart.js'] = [];
  _$jscoverage['middleware/multipart.js'][12] = 0;
  _$jscoverage['middleware/multipart.js'][21] = 0;
  _$jscoverage['middleware/multipart.js'][22] = 0;
  _$jscoverage['middleware/multipart.js'][52] = 0;
  _$jscoverage['middleware/multipart.js'][53] = 0;
  _$jscoverage['middleware/multipart.js'][55] = 0;
  _$jscoverage['middleware/multipart.js'][59] = 0;
  _$jscoverage['middleware/multipart.js'][60] = 0;
  _$jscoverage['middleware/multipart.js'][61] = 0;
  _$jscoverage['middleware/multipart.js'][62] = 0;
  _$jscoverage['middleware/multipart.js'][64] = 0;
  _$jscoverage['middleware/multipart.js'][67] = 0;
  _$jscoverage['middleware/multipart.js'][70] = 0;
  _$jscoverage['middleware/multipart.js'][73] = 0;
  _$jscoverage['middleware/multipart.js'][76] = 0;
  _$jscoverage['middleware/multipart.js'][77] = 0;
  _$jscoverage['middleware/multipart.js'][79] = 0;
  _$jscoverage['middleware/multipart.js'][84] = 0;
  _$jscoverage['middleware/multipart.js'][85] = 0;
  _$jscoverage['middleware/multipart.js'][88] = 0;
  _$jscoverage['middleware/multipart.js'][89] = 0;
  _$jscoverage['middleware/multipart.js'][90] = 0;
  _$jscoverage['middleware/multipart.js'][91] = 0;
  _$jscoverage['middleware/multipart.js'][92] = 0;
  _$jscoverage['middleware/multipart.js'][94] = 0;
  _$jscoverage['middleware/multipart.js'][98] = 0;
  _$jscoverage['middleware/multipart.js'][99] = 0;
  _$jscoverage['middleware/multipart.js'][102] = 0;
  _$jscoverage['middleware/multipart.js'][103] = 0;
  _$jscoverage['middleware/multipart.js'][106] = 0;
  _$jscoverage['middleware/multipart.js'][107] = 0;
  _$jscoverage['middleware/multipart.js'][108] = 0;
  _$jscoverage['middleware/multipart.js'][109] = 0;
  _$jscoverage['middleware/multipart.js'][111] = 0;
  _$jscoverage['middleware/multipart.js'][114] = 0;
  _$jscoverage['middleware/multipart.js'][115] = 0;
  _$jscoverage['middleware/multipart.js'][116] = 0;
  _$jscoverage['middleware/multipart.js'][117] = 0;
  _$jscoverage['middleware/multipart.js'][118] = 0;
  _$jscoverage['middleware/multipart.js'][119] = 0;
  _$jscoverage['middleware/multipart.js'][121] = 0;
  _$jscoverage['middleware/multipart.js'][125] = 0;
  _$jscoverage['middleware/multipart.js'][127] = 0;
  _$jscoverage['middleware/multipart.js'][128] = 0;
  _$jscoverage['middleware/multipart.js'][129] = 0;
}
_$jscoverage['middleware/multipart.js'][12]++;
var formidable = require("formidable"), _limit = require("./limit"), utils = require("../utils"), qs = require("qs");
_$jscoverage['middleware/multipart.js'][21]++;
function noop(req, res, next) {
  _$jscoverage['middleware/multipart.js'][22]++;
  next();
}
_$jscoverage['middleware/multipart.js'][52]++;
exports = module.exports = (function (options) {
  _$jscoverage['middleware/multipart.js'][53]++;
  options = options || {};
  _$jscoverage['middleware/multipart.js'][55]++;
  var limit = options.limit? _limit(options.limit): noop;
  _$jscoverage['middleware/multipart.js'][59]++;
  return (function multipart(req, res, next) {
  _$jscoverage['middleware/multipart.js'][60]++;
  if (req._body) {
    _$jscoverage['middleware/multipart.js'][60]++;
    return next();
  }
  _$jscoverage['middleware/multipart.js'][61]++;
  req.body = req.body || {};
  _$jscoverage['middleware/multipart.js'][62]++;
  req.files = req.files || {};
  _$jscoverage['middleware/multipart.js'][64]++;
  if (! utils.hasBody(req)) {
    _$jscoverage['middleware/multipart.js'][64]++;
    return next();
  }
  _$jscoverage['middleware/multipart.js'][67]++;
  if ("GET" == req.method || "HEAD" == req.method) {
    _$jscoverage['middleware/multipart.js'][67]++;
    return next();
  }
  _$jscoverage['middleware/multipart.js'][70]++;
  if ("multipart/form-data" != utils.mime(req)) {
    _$jscoverage['middleware/multipart.js'][70]++;
    return next();
  }
  _$jscoverage['middleware/multipart.js'][73]++;
  req._body = true;
  _$jscoverage['middleware/multipart.js'][76]++;
  limit(req, res, (function (err) {
  _$jscoverage['middleware/multipart.js'][77]++;
  if (err) {
    _$jscoverage['middleware/multipart.js'][77]++;
    return next(err);
  }
  _$jscoverage['middleware/multipart.js'][79]++;
  var form = new formidable.IncomingForm(), data = {}, files = {}, done;
  _$jscoverage['middleware/multipart.js'][84]++;
  Object.keys(options).forEach((function (key) {
  _$jscoverage['middleware/multipart.js'][85]++;
  form[key] = options[key];
}));
  _$jscoverage['middleware/multipart.js'][88]++;
  function ondata(name, val, data) {
    _$jscoverage['middleware/multipart.js'][89]++;
    if (Array.isArray(data[name])) {
      _$jscoverage['middleware/multipart.js'][90]++;
      data[name].push(val);
    }
    else {
      _$jscoverage['middleware/multipart.js'][91]++;
      if (data[name]) {
        _$jscoverage['middleware/multipart.js'][92]++;
        data[name] = [data[name], val];
      }
      else {
        _$jscoverage['middleware/multipart.js'][94]++;
        data[name] = val;
      }
    }
}
  _$jscoverage['middleware/multipart.js'][98]++;
  form.on("field", (function (name, val) {
  _$jscoverage['middleware/multipart.js'][99]++;
  ondata(name, val, data);
}));
  _$jscoverage['middleware/multipart.js'][102]++;
  form.on("file", (function (name, val) {
  _$jscoverage['middleware/multipart.js'][103]++;
  ondata(name, val, files);
}));
  _$jscoverage['middleware/multipart.js'][106]++;
  form.on("error", (function (err) {
  _$jscoverage['middleware/multipart.js'][107]++;
  if (! options.defer) {
    _$jscoverage['middleware/multipart.js'][108]++;
    err.status = 400;
    _$jscoverage['middleware/multipart.js'][109]++;
    next(err);
  }
  _$jscoverage['middleware/multipart.js'][111]++;
  done = true;
}));
  _$jscoverage['middleware/multipart.js'][114]++;
  form.on("end", (function () {
  _$jscoverage['middleware/multipart.js'][115]++;
  if (done) {
    _$jscoverage['middleware/multipart.js'][115]++;
    return;
  }
  _$jscoverage['middleware/multipart.js'][116]++;
  try {
    _$jscoverage['middleware/multipart.js'][117]++;
    req.body = qs.parse(data);
    _$jscoverage['middleware/multipart.js'][118]++;
    req.files = qs.parse(files);
    _$jscoverage['middleware/multipart.js'][119]++;
    if (! options.defer) {
      _$jscoverage['middleware/multipart.js'][119]++;
      next();
    }
  }
  catch (err) {
    _$jscoverage['middleware/multipart.js'][121]++;
    form.emit("error", err);
  }
}));
  _$jscoverage['middleware/multipart.js'][125]++;
  form.parse(req);
  _$jscoverage['middleware/multipart.js'][127]++;
  if (options.defer) {
    _$jscoverage['middleware/multipart.js'][128]++;
    req.form = form;
    _$jscoverage['middleware/multipart.js'][129]++;
    next();
  }
}));
});
});
_$jscoverage['middleware/multipart.js'].source = ["/*!"," * Connect - multipart"," * Copyright(c) 2010 Sencha Inc."," * Copyright(c) 2011 TJ Holowaychuk"," * MIT Licensed"," */","","/**"," * Module dependencies."," */","","var formidable = require('formidable')","  , _limit = require('./limit')","  , utils = require('../utils')","  , qs = require('qs');","","/**"," * noop middleware."," */","","function noop(req, res, next) {","  next();","}","","/**"," * Multipart:"," * "," * Parse multipart/form-data request bodies,"," * providing the parsed object as `req.body`"," * and `req.files`."," *"," * Configuration:"," *"," *  The options passed are merged with [formidable](https://github.com/felixge/node-formidable)'s"," *  `IncomingForm` object, allowing you to configure the upload directory,"," *  size limits, etc. For example if you wish to change the upload dir do the following."," *"," *     app.use(connect.multipart({ uploadDir: path }));"," *"," * Options:"," *"," *   - `limit`  byte limit defaulting to none"," *   - `defer`  defers processing and exposes the Formidable form object as `req.form`."," *              `next()` is called without waiting for the form's \"end\" event."," *              This option is useful if you need to bind to the \"progress\" event, for example."," *"," * @param {Object} options"," * @return {Function}"," * @api public"," */","","exports = module.exports = function(options){","  options = options || {};","","  var limit = options.limit","    ? _limit(options.limit)","    : noop;","","  return function multipart(req, res, next) {","    if (req._body) return next();","    req.body = req.body || {};","    req.files = req.files || {};","","    if (!utils.hasBody(req)) return next();","","    // ignore GET","    if ('GET' == req.method || 'HEAD' == req.method) return next();","","    // check Content-Type","    if ('multipart/form-data' != utils.mime(req)) return next();","","    // flag as parsed","    req._body = true;","","    // parse","    limit(req, res, function(err){","      if (err) return next(err);","","      var form = new formidable.IncomingForm","        , data = {}","        , files = {}","        , done;","","      Object.keys(options).forEach(function(key){","        form[key] = options[key];","      });","","      function ondata(name, val, data){","        if (Array.isArray(data[name])) {","          data[name].push(val);","        } else if (data[name]) {","          data[name] = [data[name], val];","        } else {","          data[name] = val;","        }","      }","","      form.on('field', function(name, val){","        ondata(name, val, data);","      });","","      form.on('file', function(name, val){","        ondata(name, val, files);","      });","","      form.on('error', function(err){","        if (!options.defer) {","          err.status = 400;","          next(err);","        }","        done = true;","      });","","      form.on('end', function(){","        if (done) return;","        try {","          req.body = qs.parse(data);","          req.files = qs.parse(files);","          if (!options.defer) next();","        } catch (err) {","          form.emit('error', err);","        }","      });","","      form.parse(req);","","      if (options.defer) {","        req.form = form;","        next();","      }","    });","  }","};"];
