Helper Methods

Display Name

A helper to suggest a display name:

  • name if name is set and is not empty

  • infohash as a fallback

$displayName = TorrentFile::fromPath('~/isos/debian.iso')
    ->getDisplayName(); // 'debian.iso'

File Name

A helper to suggest a file name: getDisplayName() + '.torrent'

$filename = TorrentFile::fromPath('~/isos/debian.iso')
    ->getFileName(); // 'debian.iso.torrent'

Raw Data


Since 2.2 getRawData() is guaranteed to return the structure as it is encoded in the bencoded torrent file. In earlier versions it returned whatever junk TorrentFile stored internally.

Changed in version 2.2: Consistent return format

Changed in version 4.0: Uses ListObject and DictObject instances instead of array

A helper method that dumps raw torrent data as an array-like structure.

// get raw data (in readonly array-like structures)
$data = $torrent->getRawData();
// info dictionary
// fields
var_dump($data['creation date']);
// etc...

// get a real array
$array = $data->getArray();