项目作者: webtorrent

项目描述 :
Create .torrent files
高级语言: JavaScript
项目地址: git://github.com/webtorrent/create-torrent.git
创建时间: 2014-05-21T08:53:36Z
项目社区:https://github.com/webtorrent/create-torrent

开源协议:MIT License

下载


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

  1. npm install create-torrent

usage

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

  1. import createTorrent from 'create-torrent'
  2. import fs from 'fs'
  3. createTorrent('/path/to/folder', (err, torrent) => {
  4. if (!err) {
  5. // `torrent` is a Buffer with the contents of the new .torrent file
  6. fs.writeFile('my.torrent', torrent)
  7. }
  8. })

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.

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

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:

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

command line

  1. usage: create-torrent <directory OR file> {-o outfile.torrent}
  2. Create a torrent file from a directory or file.
  3. If an output file isn\'t specified with `-o`, the torrent file will be
  4. written to stdout.

license

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