{"size": 905, "ext": "js", "max_stars_repo_path": "src/helper/route.js", "max_stars_repo_name": "chenglin33/anydoor", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/helper/route.js", "max_issues_repo_name": "chenglin33/anydoor", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/helper/route.js", "max_forks_repo_name": "chenglin33/anydoor", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 31.2068965517, "max_line_length": 74, "alphanum_fraction": 0.6287292818}
const fs = require('fs')
const promisify = require('util').promisify
const stat = promisify(fs.stat)
const readdir = promisify(fs.readdir)

module.exports = async function (req, res, fillPath) {
  try {
    const stats = await stat(fillPath)
    if (stats.isFile()) {
      res.statusCode = 200
      res.setHeader('Content-Type', 'text/plain')
      // fs.readFile(fillPath, (err, data) => { // 数据全部读完才吐给res 读取数据慢 不推荐
      //   res.end(data)
      // })
      fs.createReadStream(fillPath).pipe(res) // 通过流的方式慢慢读出来吐给res 读取数据快 推荐
    } else if(stats.isDirectory()) { //为文件夹
      const files = await readdir(fillPath)
      res.statusCode = 200
      res.setHeader('Content-Type', 'text/plain')
      res.end(files.join(','))
    }
  } catch (ex) {
    console.error(ex)
    res.statusCode = 404
    res.setHeader('Content-Type', 'text/plain')
    res.end(`${fillPath} is not a directory or file`)
  }
}
