Skip to content

Commit

Permalink
perf: drop simple-get (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaUnknown authored Jan 25, 2023
1 parent 5e5fcec commit 0176518
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
23 changes: 12 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import bencode from 'bencode'
import fs from 'fs' // browser exclude
import get from 'simple-get'
import fetch from 'cross-fetch-ponyfill'
import magnet from 'magnet-uri'
import path from 'path'
import { hash, arr2hex, text2arr, arr2text } from 'uint8-util'
Expand Down Expand Up @@ -75,17 +75,18 @@ async function parseTorrentRemote (torrentId, opts, cb) {
} catch (err) {
return cb(new Error(`Error converting Blob: ${err.message}`))
}
} else if (typeof get === 'function' && /^https?:/.test(torrentId)) {
// http, or https url to torrent file
opts = Object.assign({
url: torrentId,
timeout: 30 * 1000,
headers: { 'user-agent': 'WebTorrent (https://webtorrent.io)' }
}, opts)
get.concat(opts, (err, res, torrentBuf) => {
if (err) return cb(new Error(`Error downloading torrent: ${err.message}`))
} else if (/^https?:/.test(torrentId)) {
try {
const res = await fetch(torrentId, {
headers: { 'user-agent': 'WebTorrent (https://webtorrent.io)' },
signal: AbortSignal.timeout(30 * 1000),
...opts
})
const torrentBuf = new Uint8Array(await res.arrayBuffer())
parseOrThrow(torrentBuf)
})
} catch (err) {
return cb(new Error(`Error downloading torrent: ${err.message}`))
}
} else if (typeof fs.readFile === 'function' && typeof torrentId === 'string') {
// assume it's a filesystem path
fs.readFile(torrentId, (err, torrentBuf) => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
"type": "module",
"dependencies": {
"bencode": "^3.0.0",
"cross-fetch-ponyfill": "^1.0.1",
"get-stdin": "^9.0.0",
"magnet-uri": "^6.2.0",
"queue-microtask": "^1.2.3",
"simple-get": "^4.0.1",
"uint8-util": "^2.1.4"
},
"devDependencies": {
Expand Down

0 comments on commit 0176518

Please sign in to comment.