An ESM package that uses Web Streams API to create v1, v2 or hybrid torrents in your web browser.
🏗This package is under active development.🏗
npm i torrefy # or yarn add torrefy
import { create, encode, decode } from "torrefy";
// create a test file
const testFile = new File(
["Hello world. This is the test file content."],
"testfile.txt"
);
// calculate (hash) the meta info of the test file
const metaInfo = await create([testFile]);
// bencode meta info into a readable stream
const torrentStream = encode(metaInfo);
// tee the readable stream into two readable streams
const [torrentStream1, torrentStream2] = torrentStream.tee();
// consume the first readable stream as an array buffer
const torrentBinary = await new Response(torrentStream1).arrayBuffer();
// decode the second readable stream into meta info
const decodedMetaInfo = await decode(torrentStream2);
This package can handle input files or directories acquired from File API, File and Directory Entries API or File System Access API.