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

A helper method that dumps raw torrent data as array.

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