# 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:
  - jala/code/BitTorrent.js, line 52

##### Returns:

A new BitTorrent file.

### Methods

#### get(name)

Get a torrent property.

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | String | The name of the property.

Source:
  - jala/code/BitTorrent.js, line 124

##### Returns:

The value of the property.

#### getCreationDate()

Get the creation date of the torrent.

Source:
  - jala/code/BitTorrent.js, line 147

##### Returns:

The torrent's creation date.

#### getPieceLength()

Get the piece length of the torrent.

Source:
  - jala/code/BitTorrent.js, line 165

##### Returns:

The torrent's piece length.

#### getSourceFile()

Returns the underlying source file.

Source:
  - jala/code/BitTorrent.js, line 193

##### Returns:

The source file.

#### getTorrentFile()

Returns the underlying torrent file.

Source:
  - jala/code/BitTorrent.js, line 184

##### Returns:

The torrent file.

#### keys()

Get all available property names.

Source:
  - jala/code/BitTorrent.js, line 110

##### 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:
  - jala/code/BitTorrent.js, line 203

#### 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:
  - jala/code/BitTorrent.js, line 133

#### setCreationDate(date)

Set the creation date of the torrent.

##### Parameters:

Name | Type | Description
--- | --- | ---
`date` | Date | The desired creation date.

Source:
  - jala/code/BitTorrent.js, line 155

#### setPieceLength(length)

Set the piece length of the torrent.

##### Parameters:

Name | Type | Description
--- | --- | ---
`length` | Number | The desired piece length.

Source:
  - jala/code/BitTorrent.js, line 173

#### toString()

Get a string representation of the torrent.

Source:
  - jala/code/BitTorrent.js, line 221

##### 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:
  - jala/code/BitTorrent.js, line 304

##### 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:
  - jala/code/BitTorrent.js, line 253

##### Returns:

The encoded string.