create-torrent

Create .torrent files

create-torrent

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

npm install create-torrent

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

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

A reasonable piece length (~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).

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 (works in the browser) (must set a name property on it)
  • Node stream.Readable object (must set name and opt.pieceLength properties on it)

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`) 
  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) 
  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)) 
}

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

  • udp://tracker.publicbt.com:80
  • udp://tracker.openbittorrent.com:80
  • udp://open.demonii.com:1337
  • udp://tracker.webtorrent.io:80
  • wss://tracker.webtorrent.io (For WebRTC peers, see: WebTorrent)

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.

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.

MIT. Copyright (c) Feross Aboukhadijeh.