{"version":3,"sources":["jsdelivr-header.js","/npm/hmed-torrent@1.0.0/index.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,ACNA,aAEA,MAAM,UAAY,QAAQ,qBACpB,GAAK,IAAI,UAET,WAAa,QAAQ,qBACrB,GAAK,QAAQ,MAEb,OAAS,IAAI,WACb,YAAc,QAAQ,gBACtB,IAAM,IAAI,YAAY,UAAU,CAAC,EAAG,YAAY,QAAQ,gBAE9D,SAAS,eAAe,GACtB,MAAM,EAAY,uBAAuB,IAEzC,QAAQ,IAAI,eAAgB,GAE5B,OAAO,IAAI,GAAY,IACrB,GAAG,QACH,MAAM,EAAQ,EAAQ,MACtB,IAAI,EAAS,EAAM,OACnB,QAAQ,IAAI,qBAAqB,MAEjC,IAAI,MAAM,IAAK,GACf,IAAI,EAAW,aAAY,KACzB,IAAI,OAA0B,IAAnB,EAAQ,SAAe,GACjC,KACH,EAAM,SAAS,IACb,MAAM,EAAS,EAAK,mBACd,EAAc,GAAG,kBAAkB,EAAK,MAC9C,EACG,GAAG,OAAO,KAIT,GAHA,QAAQ,IAAI,YAAa,EAAK,MAE9B,GAAU,GACL,EAAQ,CACX,MAAM,EAAS,GAAG,OAClB,QAAQ,IAAI,eAAe,QAC3B,IAAI,OACJ,cAAc,GACd,QAAQ,MACV,KAED,KAAK,EAAY,GACpB,GAEN,CAEA,SAAS,UAAS,SAAE,EAAQ,SAAE,EAAQ,cAAE,KACzB,IAAI,YAEV,KAAK,EAAU,CAAE,KAAM,GAAG,KAAY,MAAoB,GAC/D,QAAQ,IAAI,qBAAsB,EAAQ,WAE9C,CAEA,OAAO,QAAU,CAAE,8BAAgB","file":"/npm/hmed-torrent@1.0.0/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/hmed-torrent@1.0.0/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","'use strict';\r\n\r\nconst Stopwatch = require('statman-stopwatch');\r\nconst sw = new Stopwatch();\r\n\r\nconst WebTorrent = require('webtorrent-hybrid');\r\nconst fs = require('fs');\r\n// const hash = process.argv[2];\r\nconst client = new WebTorrent();\r\nconst cliProgress = require('cli-progress');\r\nconst bar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic);\r\n\r\nfunction HmedGetTorrent(torrenthash) {\r\n  const torrentId = `magnet:?xt=urn:btih:${torrenthash}`;\r\n\r\n  console.log('torrentId:\\t', torrentId);\r\n\r\n  client.add(torrentId, (torrent) => {\r\n    sw.start();\r\n    const files = torrent.files;\r\n    let length = files.length;\r\n    console.log(`Number of Files : ${length} `);\r\n    // Stream each file to the disk\r\n    bar.start(100, 0);\r\n    let interval = setInterval(() => {\r\n      bar.update(torrent.progress * 100);\r\n    }, 3000);\r\n    files.forEach((file) => {\r\n      const source = file.createReadStream();\r\n      const destination = fs.createWriteStream(file.name);\r\n      source\r\n        .on('end', () => {\r\n          console.log('file:\\t\\t', file.name);\r\n          // close after all files are saved\r\n          length -= 1;\r\n          if (!length) {\r\n            const tempps = sw.read();\r\n            console.log(`Finished in ${tempps} ms`);\r\n            bar.stop();\r\n            clearInterval(interval);\r\n            process.exit();\r\n          }\r\n        })\r\n        .pipe(destination);\r\n    });\r\n  });\r\n}\r\n\r\nfunction HmedSeed({ fileData, fileName, fileExtension }) {\r\n  var client = new WebTorrent();\r\n\r\n  client.seed(fileData, { name: `${fileName}.${fileExtension}` }, (torrent) =>\r\n    console.log('Client is seeding:', torrent.infoHash)\r\n  );\r\n}\r\n\r\nmodule.exports = { HmedGetTorrent, HmedSeed };\r\n"]}