Helper Methods

Display Name

A helper to suggest a display name:

  • name if name is set and is not empty

  • infohash as a fallback

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

File Name

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

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

Raw Data

Warning

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.

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