6.0.18 • Published 6 months ago

create-torrent v6.0.18

Weekly downloads
3,811
License
MIT
Repository
github
Last release
6 months ago

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.

6.0.18

6 months ago

6.0.17

11 months ago

6.0.16

1 year ago

6.0.15

1 year ago

6.0.14

1 year ago

6.0.13

1 year ago

6.0.12

1 year ago

6.0.11

2 years ago

6.0.10

2 years ago

6.0.7

2 years ago

6.0.6

2 years ago

6.0.9

2 years ago

6.0.8

2 years ago

6.0.3

2 years ago

6.0.5

2 years ago

6.0.4

2 years ago

5.0.9

2 years ago

5.0.8

2 years ago

5.0.7

2 years ago

6.0.1

2 years ago

6.0.0

2 years ago

6.0.2

2 years ago

5.0.6

2 years ago

5.0.5

2 years ago

5.0.4

2 years ago

5.0.3

2 years ago

5.0.2

3 years ago

5.0.1

3 years ago

5.0.0

3 years ago

4.7.2

3 years ago

4.7.1

3 years ago

4.7.0

4 years ago

4.6.0

4 years ago

4.5.0

4 years ago

4.4.5

4 years ago

4.4.4

4 years ago

4.4.3

4 years ago

4.4.2

5 years ago

4.4.1

5 years ago

4.4.0

5 years ago

4.3.1

5 years ago

4.3.0

5 years ago

4.2.2

5 years ago

4.2.1

5 years ago

4.2.0

5 years ago

4.1.0

5 years ago

4.0.0

5 years ago

3.33.0

6 years ago

3.32.1

6 years ago

3.32.0

7 years ago

3.31.0

7 years ago

3.30.0

7 years ago

3.29.2

8 years ago

3.29.1

8 years ago

3.29.0

8 years ago

3.28.0

8 years ago

3.27.0

8 years ago

3.26.1

8 years ago

3.26.0

8 years ago

3.25.3

8 years ago

3.25.2

8 years ago

3.25.1

8 years ago

3.25.0

8 years ago

3.24.8

8 years ago

3.24.7

8 years ago

3.24.6

8 years ago

3.24.5

9 years ago

3.24.4

9 years ago

3.24.3

9 years ago

3.24.2

9 years ago

3.24.1

9 years ago

3.24.0

9 years ago

3.23.1

9 years ago

3.23.0

9 years ago

3.22.2

9 years ago

3.22.1

9 years ago

3.22.0

9 years ago

3.21.0

9 years ago

3.20.3

9 years ago

3.20.2

9 years ago

3.20.1

9 years ago

3.20.0

9 years ago

3.19.0

9 years ago

3.18.1

9 years ago

3.18.0

9 years ago

3.17.2

9 years ago

3.17.1

9 years ago

3.17.0

9 years ago

3.16.0

9 years ago

3.15.1

9 years ago

3.15.0

9 years ago

3.14.1

9 years ago

3.14.0

9 years ago

3.13.0

10 years ago

3.12.0

10 years ago

3.11.1

10 years ago

3.11.0

10 years ago

3.10.3

10 years ago

3.10.2

10 years ago

3.10.1

10 years ago

3.10.0

10 years ago

3.9.2

10 years ago

3.9.1

10 years ago

3.9.0

10 years ago

3.8.0

10 years ago

3.7.2

10 years ago

3.7.1

10 years ago

3.7.0

10 years ago

3.6.1

10 years ago

3.6.0

10 years ago

3.5.1

10 years ago

3.5.0

10 years ago

3.4.0

10 years ago

3.3.1

10 years ago

3.3.0

10 years ago

3.2.2

10 years ago

3.2.1

10 years ago

3.2.0

10 years ago

3.1.1

10 years ago

3.1.0

10 years ago

3.0.1

10 years ago

3.0.0

10 years ago

2.8.2

10 years ago

2.8.1

10 years ago

2.8.0

10 years ago

2.7.0

10 years ago

2.6.0

10 years ago

2.5.0

10 years ago

2.4.0

10 years ago

2.3.0

10 years ago

2.2.0

10 years ago

2.1.0

10 years ago

2.0.1

10 years ago

2.0.0

10 years ago

1.2.0

11 years ago

1.1.0

11 years ago

1.0.2

11 years ago

1.0.1

11 years ago

1.0.0

11 years ago