{"size": 577, "ext": "js", "max_stars_repo_path": "lib/multiload.js", "max_stars_repo_name": "substack/hyperboot-reader", "max_stars_repo_stars_event_min_datetime": "2015-10-05T14:01:51.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-05T09:01:15.000Z", "max_issues_repo_path": "lib/multiload.js", "max_issues_repo_name": "substack/hyperboot-reader", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lib/multiload.js", "max_forks_repo_name": "substack/hyperboot-reader", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 8, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 26.2272727273, "max_line_length": 59, "alphanum_fraction": 0.5979202773}
var hload = require('hyperboot/lib/load/http.js')
var concat = require('concat-stream')
var WebTorrent = require('webtorrent')
var magnet = require('magnet-uri')

module.exports = function () {
  var client = new WebTorrent

  return function (href, opts, cb) {
    if (/^https?:/.test(href)) return hload(href, opts, cb)
    if (/^magnet:/.test(href)) {
      client.add(href, function (torrent) {
        var r = torrent.files[0].createReadStream()
        r.once('error', cb)
        r.pipe(concat(function (body) {
          cb(null, body)
        }))
      })
    }
  }
}
