Socket
Book a DemoInstallSign in
Socket

@ctrl/torrent-file

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ctrl/torrent-file

Parse a torrent file (name, hash, files, pieces)

Source
npmnpm
Version
2.0.3
Version published
Weekly downloads
1.8K
-10.01%
Maintainers
1
Weekly downloads
 
Created
Source

torrent-file npm coverage bundlesize

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 and keeps dependencies to a minimum.

Install

npm install @ctrl/torrent-file

API

info

The content of the metainfo file.

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

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

import fs from 'fs';
import { hash } from '@ctrl/torrent-file';

(async () => {
  const torrentHash = await hash(fs.readFileSync('myfile'));
  console.log({ torrentHash });
})()

encode

Use the built in bencode encoder

import fs from 'fs';
import { encode } from '@ctrl/torrent-file';

encode({ name: 'my string to encode' });

decode

Easily get the raw data inside a torrent file.

import fs from 'fs';
import { decode } from '@ctrl/torrent-file';

decode(fs.readFileSync('myfile'));

See Also

parse-torrent - "@ctrl/torrent-file" torrent parsing based very heavily off this project
node-bencode - bencoder built into this project heavily based off this project

FAQs

Package last updated on 06 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts