Security News
Research
Supply Chain Attack on Rspack npm Packages Injects Cryptojacking Malware
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
create-torrent
Advanced tools
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:
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).
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)
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:
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:
const buf = Buffer.from('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.
MIT. Copyright (c) Feross Aboukhadijeh and WebTorrent, LLC.
FAQs
Create .torrent files
The npm package create-torrent receives a total of 4,247 weekly downloads. As such, create-torrent popularity was classified as popular.
We found that create-torrent demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 9 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.
Security News
Sonar’s acquisition of Tidelift highlights a growing industry shift toward sustainable open source funding, addressing maintainer burnout and critical software dependencies.