webtorrent / parse-torrent

Parse a torrent identifier (magnet uri, .torrent file, info hash)
https://webtorrent.io
MIT License
441 stars 82 forks source link

await ParseTorrent #186

Closed damienmillet closed 6 months ago

damienmillet commented 6 months ago

What version of this package are you using? 11.0.16 What operating system, Node.js, and npm version? MacOs, NodeJs v22.2.0 with NextJS 14.2.3, npm 10.7.0 What happened? ParseTorrent isn't typed as promise but work only with the await keyword What did you expect to happen?

this is an example, maybe I'm wrong

    const fileBlob = await file.arrayBuffer();
    const fileBuffer = Buffer.from(fileBlob);
    const fileName = file.name;
    const torrent = ParseTorrent(fileBuffer);
    const magnet = toMagnetURI(torrent);
    // return only "magnet:?"
    const torrent = await ParseTorrent(fileBuffer); // but isn't typed as Promise
    const magnet = toMagnetURI(torrent);
    // return a correct magnet link

Are you willing to submit a pull request to fix this bug? no

ThaUnknown commented 6 months ago

webtorrent and parsetorrent doesn't provide types, you're likely using some 3rd party library for types which is incorrect