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 (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 (~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).
createTorrent(input, [opts], function callback (err, torrent) {})
Create a new
.torrent
file.
input
can be any of the following:
<input>
or drag and drop)
File
objects)
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)
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:
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:
/imgs/
the torrent name will be
imgs
.
/foo/bar/baz.txt
, the torrent name will be
baz.txt
.
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:
var buf = new Buffer('Some file content')
buf.name = 'Some file name'
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.
Install browserify from npm(browserify-lite from the debian repositories will not work for this.)
sudo apt-get install nodejs npm
sudo npm install -g browserify
Navigate to your source code directory and install the following dependencies before building.
npm install bencode block-stream2 piece-length path xtend filestream flatten fs is-file junk multistream once run-parallel simple-sha1 readable-stream
Browserify the contents of the create-torrent package.
browserify ./index.js -o create-torrent.js
Create the index page:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>InstaTorrent!</title>
<meta name="description" content="InstaTorrent!">
<meta name="author" content="eyedeekay">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<script src="create-torrent.js"></script>
</body>
</html>
and that’s all I’ve got so far.
MIT. Copyright © Feross Aboukhadijeh .
The MIT License (MIT)
Copyright (c) Feross Aboukhadijeh
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Hide license