code: function check(strategy, file, req, upstreamProxy) {
    let parsed = url.parse(file)
    file = parsed.pathname // stripped of query string.
  
    return co(function*() {
      if (strategy !== 'mirror') {
        return false
      }
      try {
        yield adapt(fs.stat, file)
        return false
      } catch(ex) {
        // file does not exist, so continue
      }
      // TODO: test coverage for mkdirp
      yield adapt(mkdirp, pathTools.dirname(file))
      let provReq = new ProvisionableRequest({
        protocol: req.protocol,
        proxy: upstreamProxy,
        method: 'GET',
        hostname: req.hostname,
        port: req.port,
        path: req.url,
      })
      provReq.send()
      let mirrResp = yield provReq.receive()
      if (mirrResp.statusCode !== 200) {
        throw new Error(`mirroring failed: ${req.fullUrl()} => ${mirrResp.statusCode}`)
      }
      let writeToFile = fs.createWriteStream(file)
      if (mirrResp.headers['content-encoding'] === 'gzip') {
        // TODO: test coverage
        let gunzip = zlib.createGunzip()
        mirrResp = mirrResp.pipe(gunzip)
      }
      yield new Promise((resolve, reject) => {
        mirrResp.pipe(writeToFile)
        mirrResp.on('end', resolve)
        writeToFile.on('error', reject)
      })
    })
  }
docs: /*
  This check() function made me scratch my head when I came back to
  it months later. It simply does too many things. It still isn't perfect,
  but hopefully now this beast is slightly easier to follow. It returns
  a promise on a boolean indicating whether or not the passed file was
  created. IF the strategy is NOT 'mirror' it resolves false since 'mirror'
  is the only strategy that creates files. Otherwise if the file exists
  it resolves false. Otherwise it has a side effect of creating the file
  by requesting out to the remote server and writing the result to the
  file, then resolves true.