mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-18 16:53:57 +00:00
18 lines
492 B
TypeScript
18 lines
492 B
TypeScript
import { parentPort } from "worker_threads";
|
|
import parseTorrent from "parse-torrent";
|
|
|
|
const port = parentPort;
|
|
if (!port) throw new Error("IllegalState");
|
|
|
|
const getTorrentBuffer = (url: string) =>
|
|
fetch(url, { method: "GET" }).then((response) =>
|
|
response.arrayBuffer().then((buffer) => Buffer.from(buffer))
|
|
);
|
|
|
|
port.on("message", async (url: string) => {
|
|
const buffer = await getTorrentBuffer(url);
|
|
const torrent = await parseTorrent(buffer);
|
|
|
|
port.postMessage(torrent);
|
|
});
|