• Stars
    star
    342
  • Rank 123,697 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 10 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Create .torrent files

create-torrent ci npm downloads javascript style guide

Create .torrent files

creation

This module is used by WebTorrent! This module works in node.js and the browser (with browserify).

install

npm install create-torrent

usage

The simplest way to use create-torrent is like this:

import createTorrent from 'create-torrent'
import fs from 'fs'

createTorrent('/path/to/folder', (err, torrent) => {
  if (!err) {
    // `torrent` is a Buffer with the contents of the new .torrent file
    fs.writeFile('my.torrent', torrent)
  }
})

A reasonable piece length (approx. 1024 pieces) will automatically be selected for the .torrent file, or you can override it if you want a different size (See API docs below).

api

createTorrent(input, [opts], function callback (err, torrent) {})

Create a new .torrent file.

input can be any of the following:

  • path to the file or folder on filesystem (string)
  • W3C File object (from an <input> or drag and drop)
  • W3C FileList object (basically an array of File objects)
  • Node Buffer object
  • Node stream.Readable object

Or, an array of string, File, Buffer, or stream.Readable objects.

opts is optional and allows you to set special settings on the produced .torrent file.

{
  name: String,             // name of the torrent (default = basename of `path`, or 1st file's name)
  comment: String,          // free-form textual comments of the author
  createdBy: String,        // name and version of program used to create torrent
  creationDate: Date        // creation time in UNIX epoch format (default = now)
  filterJunkFiles: Boolean, // remove hidden and other junk files? (default = true)
  private: Boolean,         // is this a private .torrent? (default = false)
  pieceLength: Number,      // force a custom piece length (number of bytes)
  announceList: [[String]], // custom trackers (array of arrays of strings) (see [bep12](http://www.bittorrent.org/beps/bep_0012.html))
  urlList: [String],        // web seed urls (see [bep19](http://www.bittorrent.org/beps/bep_0019.html))
  info: Object,             // add non-standard info dict entries, e.g. info.source, a convention for cross-seeding
  onProgress: Function      // called with the number of bytes hashed and estimated total size after every piece
}

If announceList is omitted, the following trackers will be included automatically:

  • udp://tracker.leechers-paradise.org:6969
  • udp://tracker.coppersurfer.tk:6969
  • udp://tracker.opentrackr.org:1337
  • udp://explodie.org:6969
  • udp://tracker.empire-js.us:1337
  • wss://tracker.btorrent.xyz
  • wss://tracker.openwebtorrent.com
  • wss://tracker.webtorrent.dev

Trackers that start with wss:// are for WebRTC peers. See WebTorrent to learn more.

callback is called with an error and a Buffer of the torrent data. It is up to you to save it to a file if that's what you want to do.

Note: Every torrent is required to have a name. If one is not explicitly provided through opts.name, one will be determined automatically using the following logic:

  • If all files share a common path prefix, that will be used. For example, if all file paths start with /imgs/ the torrent name will be imgs.
  • Otherwise, the first file that has a name will determine the torrent name. For example, if the first file is /foo/bar/baz.txt, the torrent name will be baz.txt.
  • If no files have names (say that all files are Buffer or Stream objects), then a name like "Unnamed Torrent " will be generated.

Note: Every file is required to have a name. For filesystem paths or W3C File objects, the name is included in the object. For Buffer or Readable stream types, a name property can be set on the object, like this:

const buf = Buffer.from('Some file content')
buf.name = 'Some file name'

command line

usage: create-torrent <directory OR file> {-o outfile.torrent}

Create a torrent file from a directory or file.

If an output file isn\'t specified with `-o`, the torrent file will be
written to stdout.

license

MIT. Copyright (c) Feross Aboukhadijeh and WebTorrent, LLC.

More Repositories

1

webtorrent

⚡️ Streaming torrent client for the web
JavaScript
29,385
star
2

webtorrent-desktop

❤️ Streaming torrent app for Mac, Windows, and Linux
JavaScript
9,659
star
3

instant.io

🚀 Streaming file transfer over WebTorrent (torrents on the web)
JavaScript
3,423
star
4

bittorrent-tracker

🌊 Simple, robust, BitTorrent tracker (client & server) implementation
JavaScript
1,744
star
5

bittorrent-dht

🕸 Simple, robust, BitTorrent DHT implementation
JavaScript
1,216
star
6

webtorrent-cli

WebTorrent, the streaming torrent client. For the command line.
JavaScript
1,154
star
7

webtorrent-hybrid

WebTorrent (with WebRTC support in Node.js)
JavaScript
518
star
8

parse-torrent

Parse a torrent identifier (magnet uri, .torrent file, info hash)
JavaScript
438
star
9

bittorrent-protocol

Simple, robust, BitTorrent peer wire protocol implementation
JavaScript
342
star
10

magnet-uri

Parse a magnet URI and return an object of keys/values
JavaScript
221
star
11

torrent-discovery

Discover BitTorrent and WebTorrent peers
JavaScript
216
star
12

node-bencode

bencode de/encoder for nodejs
JavaScript
165
star
13

webtorrent.io

The code that runs the WebTorrent website
JavaScript
125
star
14

ut_metadata

BitTorrent Extension for Peers to Send Metadata Files (BEP 9)
JavaScript
110
star
15

bittorrent-peerid

Map a BitTorrent peer ID to a human-readable client name and version
JavaScript
65
star
16

parse-torrent-file

DEPRECATED: Parse a .torrent file and return an object of keys/values
JavaScript
63
star
17

ut_pex

Implementation of ut_pex bittorrent protocol (PEX) for webtorrent
JavaScript
58
star
18

workshop

Learn WebTorrent and WebRTC in a guided workshop!
48
star
19

bittorrent-lsd

Local Service Discovery (BEP14) implementation
JavaScript
35
star
20

fs-chunk-store

Filesystem (fs) chunk store that is abstract-chunk-store compliant
JavaScript
33
star
21

torrent-piece

Torrent piece abstraction
JavaScript
23
star
22

webtorrent-fixtures

Sample torrent files for the WebTorrent test suite
JavaScript
22
star
23

load-ip-set

download and parse ip-set (blocklist) files
JavaScript
22
star
24

lt_donthave

The BitTorrent lt_donthave extension (BEP 54)
JavaScript
11
star
25

addr-to-ip-port

Convert an "address:port" string to an array [address:string, port:number]
JavaScript
10
star
26

bep53-range

Parse and compose Magnet URI extension (BEP53) ranges
JavaScript
9
star
27

string2compact

Convert 'hostname:port' strings to BitTorrent's compact ip/host binary returned by Trackers
JavaScript
9
star
28

renovate-config

Renovate's config
1
star
29

semantic-release-config

JavaScript
1
star
30

.github

1
star