Class: BitTorrent

jala.BitTorrent(trackerUrl, filePath)

This class provides methods to create a BitTorrent metadata file from any desired file.

Constructor

new BitTorrent(trackerUrl, filePath)

Constructs a new BitTorrent file.
Parameters:
Name Type Description
trackerUrl String The URL string of the tracker.
filePath String The path to the original file.
Source:
Returns:
A new BitTorrent file.

Methods

get(name)

Get a torrent property.
Parameters:
Name Type Description
name String The name of the property.
Source:
Returns:
The value of the property.

getCreationDate()

Get the creation date of the torrent.
Source:
Returns:
The torrent's creation date.

getPieceLength()

Get the piece length of the torrent.
Source:
Returns:
The torrent's piece length.

getSourceFile()

Returns the underlying source file.
Source:
Returns:
The source file.

getTorrentFile()

Returns the underlying torrent file.
Source:
Returns:
The torrent file.

keys()

Get all available property names.
Source:
Returns:
The list of property names.

save(filename)

Saves the torrent as file.
Parameters:
Name Type Description
filename String An optional name for the torrent file. If no name is given it will be composed from name of source file as defined in the torrent plus the ending ".torrent".
Source:

set(name, value)

Set a torrent property.
Parameters:
Name Type Description
name String The name of the property.
value Object The property's value.
Source:

setCreationDate(date)

Set the creation date of the torrent.
Parameters:
Name Type Description
date Date The desired creation date.
Source:

setPieceLength(length)

Set the piece length of the torrent.
Parameters:
Name Type Description
length Number The desired piece length.
Source:

toString()

Get a string representation of the torrent.
Source:
Returns:
The torrent as string.

(static) bdecode(code)

The bdecode method. Turns an encoded string into a corresponding JavaScript object structure. FIXME: Handle with caution...
Parameters:
Name Type Description
code String The encoded string.
Source:
Returns:
The decoded JavaScript structure.

(static) bencode(obj)

The bencode method. Turns an arbitrary JavaScript object structure into a corresponding encoded string.
Parameters:
Name Type Description
obj Object The target JavaScript object.
Source:
Returns:
The encoded string.