Parse a torrent file (name, hash, files, pieces)
npm install @cao-mei-you-ren/torrent-file> Parse a torrent file and read encoded data.
This project is based on parse-torrent and node-bencode to parse the data of a torrent file. This library implements its own bencode encoder and decoder that does not use Buffer.
console
npm install @ctrl/torrent-file
`$3
##### info
The content of the metainfo file.
`ts
import fs from 'fs';
import { info } from '@ctrl/torrent-file';const torrentInfo = info(fs.readFileSync('myfile'));
console.log({ torrentInfo });
`##### files
data about the files described in the torrent file, includes hashes of the pieces
`ts
import fs from 'fs';
import { files } from '@ctrl/torrent-file';const torrentFiles = files(fs.readFileSync('myfile'));
console.log({ torrentFiles });
`##### hash
sha1 of torrent file info. This hash is commenly used by torrent clients as the ID of the torrent. It is async and sha1 encoding is handled by crypto-hash
`ts
import fs from 'fs';
import { hash } from '@ctrl/torrent-file';(async () => {
const torrentHash = await hash(fs.readFileSync('myfile'));
console.log({ torrentHash });
})()
``