/* automatically generated by JSCoverage - do not edit */
if (typeof _$jscoverage === 'undefined') _$jscoverage = {};
if (! _$jscoverage['middleware/directory.js']) {
  _$jscoverage['middleware/directory.js'] = [];
  _$jscoverage['middleware/directory.js'][17] = 0;
  _$jscoverage['middleware/directory.js'][29] = 0;
  _$jscoverage['middleware/directory.js'][48] = 0;
  _$jscoverage['middleware/directory.js'][49] = 0;
  _$jscoverage['middleware/directory.js'][52] = 0;
  _$jscoverage['middleware/directory.js'][53] = 0;
  _$jscoverage['middleware/directory.js'][58] = 0;
  _$jscoverage['middleware/directory.js'][59] = 0;
  _$jscoverage['middleware/directory.js'][61] = 0;
  _$jscoverage['middleware/directory.js'][70] = 0;
  _$jscoverage['middleware/directory.js'][73] = 0;
  _$jscoverage['middleware/directory.js'][76] = 0;
  _$jscoverage['middleware/directory.js'][77] = 0;
  _$jscoverage['middleware/directory.js'][81] = 0;
  _$jscoverage['middleware/directory.js'][84] = 0;
  _$jscoverage['middleware/directory.js'][85] = 0;
  _$jscoverage['middleware/directory.js'][86] = 0;
  _$jscoverage['middleware/directory.js'][87] = 0;
  _$jscoverage['middleware/directory.js'][88] = 0;
  _$jscoverage['middleware/directory.js'][91] = 0;
  _$jscoverage['middleware/directory.js'][92] = 0;
  _$jscoverage['middleware/directory.js'][93] = 0;
  _$jscoverage['middleware/directory.js'][94] = 0;
  _$jscoverage['middleware/directory.js'][99] = 0;
  _$jscoverage['middleware/directory.js'][109] = 0;
  _$jscoverage['middleware/directory.js'][110] = 0;
  _$jscoverage['middleware/directory.js'][111] = 0;
  _$jscoverage['middleware/directory.js'][112] = 0;
  _$jscoverage['middleware/directory.js'][113] = 0;
  _$jscoverage['middleware/directory.js'][114] = 0;
  _$jscoverage['middleware/directory.js'][115] = 0;
  _$jscoverage['middleware/directory.js'][120] = 0;
  _$jscoverage['middleware/directory.js'][121] = 0;
  _$jscoverage['middleware/directory.js'][122] = 0;
  _$jscoverage['middleware/directory.js'][131] = 0;
  _$jscoverage['middleware/directory.js'][132] = 0;
  _$jscoverage['middleware/directory.js'][133] = 0;
  _$jscoverage['middleware/directory.js'][134] = 0;
  _$jscoverage['middleware/directory.js'][135] = 0;
  _$jscoverage['middleware/directory.js'][142] = 0;
  _$jscoverage['middleware/directory.js'][143] = 0;
  _$jscoverage['middleware/directory.js'][144] = 0;
  _$jscoverage['middleware/directory.js'][145] = 0;
  _$jscoverage['middleware/directory.js'][146] = 0;
  _$jscoverage['middleware/directory.js'][153] = 0;
  _$jscoverage['middleware/directory.js'][154] = 0;
  _$jscoverage['middleware/directory.js'][155] = 0;
  _$jscoverage['middleware/directory.js'][156] = 0;
  _$jscoverage['middleware/directory.js'][157] = 0;
  _$jscoverage['middleware/directory.js'][165] = 0;
  _$jscoverage['middleware/directory.js'][166] = 0;
  _$jscoverage['middleware/directory.js'][167] = 0;
  _$jscoverage['middleware/directory.js'][170] = 0;
  _$jscoverage['middleware/directory.js'][171] = 0;
  _$jscoverage['middleware/directory.js'][172] = 0;
  _$jscoverage['middleware/directory.js'][173] = 0;
  _$jscoverage['middleware/directory.js'][176] = 0;
  _$jscoverage['middleware/directory.js'][194] = 0;
  _$jscoverage['middleware/directory.js'][195] = 0;
  _$jscoverage['middleware/directory.js'][196] = 0;
  _$jscoverage['middleware/directory.js'][208] = 0;
  _$jscoverage['middleware/directory.js'][209] = 0;
  _$jscoverage['middleware/directory.js'][210] = 0;
  _$jscoverage['middleware/directory.js'][218] = 0;
}
_$jscoverage['middleware/directory.js'][17]++;
var fs = require("fs"), parse = require("url").parse, utils = require("../utils"), path = require("path"), normalize = path.normalize, extname = path.extname, join = path.join;
_$jscoverage['middleware/directory.js'][29]++;
var cache = {};
_$jscoverage['middleware/directory.js'][48]++;
exports = module.exports = (function directory(root, options) {
  _$jscoverage['middleware/directory.js'][49]++;
  options = options || {};
  _$jscoverage['middleware/directory.js'][52]++;
  if (! root) {
    _$jscoverage['middleware/directory.js'][52]++;
    throw new Error("directory() root path required");
  }
  _$jscoverage['middleware/directory.js'][53]++;
  var hidden = options.hidden, icons = options.icons, filter = options.filter, root = normalize(root);
  _$jscoverage['middleware/directory.js'][58]++;
  return (function directory(req, res, next) {
  _$jscoverage['middleware/directory.js'][59]++;
  if ("GET" != req.method && "HEAD" != req.method) {
    _$jscoverage['middleware/directory.js'][59]++;
    return next();
  }
  _$jscoverage['middleware/directory.js'][61]++;
  var accept = req.headers.accept || "text/plain", url = parse(req.url), dir = decodeURIComponent(url.pathname), path = normalize(join(root, dir)), originalUrl = parse(req.originalUrl), originalDir = decodeURIComponent(originalUrl.pathname), showUp = path != root && path != root + "/";
  _$jscoverage['middleware/directory.js'][70]++;
  if (~ path.indexOf("\u0000")) {
    _$jscoverage['middleware/directory.js'][70]++;
    return next(utils.error(400));
  }
  _$jscoverage['middleware/directory.js'][73]++;
  if (0 != path.indexOf(root)) {
    _$jscoverage['middleware/directory.js'][73]++;
    return next(utils.error(403));
  }
  _$jscoverage['middleware/directory.js'][76]++;
  fs.stat(path, (function (err, stat) {
  _$jscoverage['middleware/directory.js'][77]++;
  if (err) {
    _$jscoverage['middleware/directory.js'][77]++;
    return "ENOENT" == err.code? next(): next(err);
  }
  _$jscoverage['middleware/directory.js'][81]++;
  if (! stat.isDirectory()) {
    _$jscoverage['middleware/directory.js'][81]++;
    return next();
  }
  _$jscoverage['middleware/directory.js'][84]++;
  fs.readdir(path, (function (err, files) {
  _$jscoverage['middleware/directory.js'][85]++;
  if (err) {
    _$jscoverage['middleware/directory.js'][85]++;
    return next(err);
  }
  _$jscoverage['middleware/directory.js'][86]++;
  if (! hidden) {
    _$jscoverage['middleware/directory.js'][86]++;
    files = removeHidden(files);
  }
  _$jscoverage['middleware/directory.js'][87]++;
  if (filter) {
    _$jscoverage['middleware/directory.js'][87]++;
    files = files.filter(filter);
  }
  _$jscoverage['middleware/directory.js'][88]++;
  files.sort();
  _$jscoverage['middleware/directory.js'][91]++;
  for (var key in exports) {
    _$jscoverage['middleware/directory.js'][92]++;
    if (~ accept.indexOf(key) || ~ accept.indexOf("*/*")) {
      _$jscoverage['middleware/directory.js'][93]++;
      exports[key](req, res, files, next, originalDir, showUp, icons);
      _$jscoverage['middleware/directory.js'][94]++;
      return;
    }
}
  _$jscoverage['middleware/directory.js'][99]++;
  next(utils.error(406));
}));
}));
});
});
_$jscoverage['middleware/directory.js'][109]++;
exports.html = (function (req, res, files, next, dir, showUp, icons) {
  _$jscoverage['middleware/directory.js'][110]++;
  fs.readFile(__dirname + "/../public/directory.html", "utf8", (function (err, str) {
  _$jscoverage['middleware/directory.js'][111]++;
  if (err) {
    _$jscoverage['middleware/directory.js'][111]++;
    return next(err);
  }
  _$jscoverage['middleware/directory.js'][112]++;
  fs.readFile(__dirname + "/../public/style.css", "utf8", (function (err, style) {
  _$jscoverage['middleware/directory.js'][113]++;
  if (err) {
    _$jscoverage['middleware/directory.js'][113]++;
    return next(err);
  }
  _$jscoverage['middleware/directory.js'][114]++;
  if (showUp) {
    _$jscoverage['middleware/directory.js'][114]++;
    files.unshift("..");
  }
  _$jscoverage['middleware/directory.js'][115]++;
  str = str.replace("{style}", style).replace("{files}", html(files, dir, icons)).replace("{directory}", dir).replace("{linked-path}", htmlPath(dir));
  _$jscoverage['middleware/directory.js'][120]++;
  res.setHeader("Content-Type", "text/html");
  _$jscoverage['middleware/directory.js'][121]++;
  res.setHeader("Content-Length", str.length);
  _$jscoverage['middleware/directory.js'][122]++;
  res.end(str);
}));
}));
});
_$jscoverage['middleware/directory.js'][131]++;
exports.json = (function (req, res, files) {
  _$jscoverage['middleware/directory.js'][132]++;
  files = JSON.stringify(files);
  _$jscoverage['middleware/directory.js'][133]++;
  res.setHeader("Content-Type", "application/json");
  _$jscoverage['middleware/directory.js'][134]++;
  res.setHeader("Content-Length", files.length);
  _$jscoverage['middleware/directory.js'][135]++;
  res.end(files);
});
_$jscoverage['middleware/directory.js'][142]++;
exports.plain = (function (req, res, files) {
  _$jscoverage['middleware/directory.js'][143]++;
  files = files.join("\n") + "\n";
  _$jscoverage['middleware/directory.js'][144]++;
  res.setHeader("Content-Type", "text/plain");
  _$jscoverage['middleware/directory.js'][145]++;
  res.setHeader("Content-Length", files.length);
  _$jscoverage['middleware/directory.js'][146]++;
  res.end(files);
});
_$jscoverage['middleware/directory.js'][153]++;
function htmlPath(dir) {
  _$jscoverage['middleware/directory.js'][154]++;
  var curr = [];
  _$jscoverage['middleware/directory.js'][155]++;
  return dir.split("/").map((function (part) {
  _$jscoverage['middleware/directory.js'][156]++;
  curr.push(part);
  _$jscoverage['middleware/directory.js'][157]++;
  return "<a href=\"" + curr.join("/") + "\">" + part + "</a>";
})).join(" / ");
}
_$jscoverage['middleware/directory.js'][165]++;
function html(files, dir, useIcons) {
  _$jscoverage['middleware/directory.js'][166]++;
  return "<ul id=\"files\">" + files.map((function (file) {
  _$jscoverage['middleware/directory.js'][167]++;
  var icon = "", classes = [];
  _$jscoverage['middleware/directory.js'][170]++;
  if (useIcons && ".." != file) {
    _$jscoverage['middleware/directory.js'][171]++;
    icon = icons[extname(file)] || icons["default"];
    _$jscoverage['middleware/directory.js'][172]++;
    icon = "<img src=\"data:image/png;base64," + load(icon) + "\" />";
    _$jscoverage['middleware/directory.js'][173]++;
    classes.push("icon");
  }
  _$jscoverage['middleware/directory.js'][176]++;
  return "<li><a href=\"" + join(dir, file) + "\" class=\"" + classes.join(" ") + "\"" + " title=\"" + file + "\">" + icon + file + "</a></li>";
})).join("\n") + "</ul>";
}
_$jscoverage['middleware/directory.js'][194]++;
function load(icon) {
  _$jscoverage['middleware/directory.js'][195]++;
  if (cache[icon]) {
    _$jscoverage['middleware/directory.js'][195]++;
    return cache[icon];
  }
  _$jscoverage['middleware/directory.js'][196]++;
  return cache[icon] = fs.readFileSync(__dirname + "/../public/icons/" + icon, "base64");
}
_$jscoverage['middleware/directory.js'][208]++;
function removeHidden(files) {
  _$jscoverage['middleware/directory.js'][209]++;
  return files.filter((function (file) {
  _$jscoverage['middleware/directory.js'][210]++;
  return "." != file[0];
}));
}
_$jscoverage['middleware/directory.js'][218]++;
var icons = {".js": "page_white_code_red.png", ".c": "page_white_c.png", ".h": "page_white_h.png", ".cc": "page_white_cplusplus.png", ".php": "page_white_php.png", ".rb": "page_white_ruby.png", ".cpp": "page_white_cplusplus.png", ".swf": "page_white_flash.png", ".pdf": "page_white_acrobat.png", "default": "page_white.png"};
_$jscoverage['middleware/directory.js'].source = ["","/*!"," * Connect - directory"," * Copyright(c) 2011 Sencha Inc."," * Copyright(c) 2011 TJ Holowaychuk"," * MIT Licensed"," */","","// TODO: icon / style for directories","// TODO: arrow key navigation","// TODO: make icons extensible","","/**"," * Module dependencies."," */","","var fs = require('fs')","  , parse = require('url').parse","  , utils = require('../utils')","  , path = require('path')","  , normalize = path.normalize","  , extname = path.extname","  , join = path.join;","","/*!"," * Icon cache."," */","","var cache = {};","","/**"," * Directory:"," *"," * Serve directory listings with the given `root` path."," *"," * Options:"," *"," *  - `hidden` display hidden (dot) files. Defaults to false."," *  - `icons`  display icons. Defaults to false."," *  - `filter` Apply this filter function to files. Defaults to false."," *"," * @param {String} root"," * @param {Object} options"," * @return {Function}"," * @api public"," */","","exports = module.exports = function directory(root, options){","  options = options || {};","","  // root required","  if (!root) throw new Error('directory() root path required');","  var hidden = options.hidden","    , icons = options.icons","    , filter = options.filter","    , root = normalize(root);","","  return function directory(req, res, next) {","    if ('GET' != req.method &amp;&amp; 'HEAD' != req.method) return next();","","    var accept = req.headers.accept || 'text/plain'","      , url = parse(req.url)","      , dir = decodeURIComponent(url.pathname)","      , path = normalize(join(root, dir))","      , originalUrl = parse(req.originalUrl)","      , originalDir = decodeURIComponent(originalUrl.pathname)","      , showUp = path != root &amp;&amp; path != root + '/';","","    // null byte(s), bad request","    if (~path.indexOf('\\0')) return next(utils.error(400));","","    // malicious path, forbidden","    if (0 != path.indexOf(root)) return next(utils.error(403));","","    // check if we have a directory","    fs.stat(path, function(err, stat){","      if (err) return 'ENOENT' == err.code","        ? next()","        : next(err);","","      if (!stat.isDirectory()) return next();","","      // fetch files","      fs.readdir(path, function(err, files){","        if (err) return next(err);","        if (!hidden) files = removeHidden(files);","        if (filter) files = files.filter(filter);","        files.sort();","","        // content-negotiation","        for (var key in exports) {","          if (~accept.indexOf(key) || ~accept.indexOf('*/*')) {","            exports[key](req, res, files, next, originalDir, showUp, icons);","            return;","          }","        }","","        // not acceptable","        next(utils.error(406));","      });","    });","  };","};","","/**"," * Respond with text/html."," */","","exports.html = function(req, res, files, next, dir, showUp, icons){","  fs.readFile(__dirname + '/../public/directory.html', 'utf8', function(err, str){","    if (err) return next(err);","    fs.readFile(__dirname + '/../public/style.css', 'utf8', function(err, style){","      if (err) return next(err);","      if (showUp) files.unshift('..');","      str = str","        .replace('{style}', style)","        .replace('{files}', html(files, dir, icons))","        .replace('{directory}', dir)","        .replace('{linked-path}', htmlPath(dir));","      res.setHeader('Content-Type', 'text/html');","      res.setHeader('Content-Length', str.length);","      res.end(str);","    });","  });","};","","/**"," * Respond with application/json."," */","","exports.json = function(req, res, files){","  files = JSON.stringify(files);","  res.setHeader('Content-Type', 'application/json');","  res.setHeader('Content-Length', files.length);","  res.end(files);","};","","/**"," * Respond with text/plain."," */","","exports.plain = function(req, res, files){","  files = files.join('\\n') + '\\n';","  res.setHeader('Content-Type', 'text/plain');","  res.setHeader('Content-Length', files.length);","  res.end(files);","};","","/**"," * Map html `dir`, returning a linked path."," */","","function htmlPath(dir) {","  var curr = [];","  return dir.split('/').map(function(part){","    curr.push(part);","    return '&lt;a href=\"' + curr.join('/') + '\"&gt;' + part + '&lt;/a&gt;';","  }).join(' / ');","}","","/**"," * Map html `files`, returning an html unordered list."," */","","function html(files, dir, useIcons) {","  return '&lt;ul id=\"files\"&gt;' + files.map(function(file){","    var icon = ''","      , classes = [];","","    if (useIcons &amp;&amp; '..' != file) {","      icon = icons[extname(file)] || icons.default;","      icon = '&lt;img src=\"data:image/png;base64,' + load(icon) + '\" /&gt;';","      classes.push('icon');","    }","","    return '&lt;li&gt;&lt;a href=\"'","      + join(dir, file)","      + '\" class=\"'","      + classes.join(' ') + '\"'","      + ' title=\"' + file + '\"&gt;'","      + icon + file + '&lt;/a&gt;&lt;/li&gt;';","","  }).join('\\n') + '&lt;/ul&gt;';","}","","/**"," * Load and cache the given `icon`."," *"," * @param {String} icon"," * @return {String}"," * @api private"," */","","function load(icon) {","  if (cache[icon]) return cache[icon];","  return cache[icon] = fs.readFileSync(__dirname + '/../public/icons/' + icon, 'base64');","}","","/**"," * Filter \"hidden\" `files`, aka files"," * beginning with a `.`."," *"," * @param {Array} files"," * @return {Array}"," * @api private"," */","","function removeHidden(files) {","  return files.filter(function(file){","    return '.' != file[0];","  });","}","","/**"," * Icon map."," */","","var icons = {","    '.js': 'page_white_code_red.png'","  , '.c': 'page_white_c.png'","  , '.h': 'page_white_h.png'","  , '.cc': 'page_white_cplusplus.png'","  , '.php': 'page_white_php.png'","  , '.rb': 'page_white_ruby.png'","  , '.cpp': 'page_white_cplusplus.png'","  , '.swf': 'page_white_flash.png'","  , '.pdf': 'page_white_acrobat.png'","  , 'default': 'page_white.png'","};"];
