File_Bittorrent2
[ class tree: File_Bittorrent2 ] [ index: File_Bittorrent2 ] [ all elements ]

Class: File_Bittorrent2_MakeTorrent

Source Location: /File_Bittorrent2-1.3.1/File/Bittorrent2/MakeTorrent.php

Class Overview


Provides a class for making .torrent files from a file or directory. Produces virtually identical torrent files as btmaketorrent.py from Bram Cohen's original BT client.


Author(s):

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 60]
Provides a class for making .torrent files from a file or directory. Produces virtually identical torrent files as btmaketorrent.py from Bram Cohen's original BT client.


[ Top ]


Class Variables

$announce =  ''

[line 80]

  • Var: The .torrent announce URL
  • Access: protected

Type:   string


[ Top ]

$announce_list = array()

[line 85]

  • Var: The .torrent announce_list extension
  • Access: protected

Type:   array


[ Top ]

$comment =  ''

[line 90]

  • Var: The .torrent comment
  • Access: protected

Type:   string


[ Top ]

$created_by =  'File_Bittorrent2_MakeTorrent $Rev: 93 $. http://pear.php.net/package/File_Bittorrent'

[line 95]

  • Var: The .torrent created by string
  • Access: protected

Type:   string


[ Top ]

$data_gap =  false

[line 120]

  • Var: The data gap used to join two files into the same piece. string if it contains data or false
  • Access: protected

Type:   string|false


[ Top ]

$files = array()

[line 115]

  • Var: The list of files (if this is a multi-file torrent)
  • Access: protected

Type:   array


[ Top ]

$fp =

[line 125]

  • Var: file pointer
  • Access: protected

Type:   resource


[ Top ]

$is_dir =  false

[line 75]

  • Var: Where or not $path is a directory
  • Access: protected

Type:   bool


[ Top ]

$is_file =  false

[line 70]

  • Var: Whether or not $path is a file
  • Access: protected

Type:   bool


[ Top ]

$is_multifile =  false

[line 135]

  • Var: Where or not we have a list of files
  • Access: protected

Type:   bool


[ Top ]

$is_private =  false

[line 140]

  • Var: Torrent is marked as 'private'.
  • Access: protected

Type:   bool


[ Top ]

$last_error =

[line 130]

  • Var: The last error object or null if no error has occurred.
  • Access: protected

Type:   mixed


[ Top ]

$name =  ''

[line 100]

  • Var: The .torrent suggested name (file/dir)
  • Access: protected

Type:   string


[ Top ]

$path =  ''

[line 65]

  • Var: Path to the file or directory to create the torrent from.
  • Access: protected

Type:   string


[ Top ]

$pieces =  ''

[line 105]

  • Var: The .torrent packed piece data
  • Access: protected

Type:   string


[ Top ]

$piece_length =  524288

[line 110]

  • Var: The size of each piece in bytes.
  • Access: protected

Type:   int


[ Top ]



Method Detail

__construct (Constructor)   [line 150]

File_Bittorrent2_MakeTorrent __construct( string $path)

Constructor

Sets up the path to the file/dir to create a torrent from


Parameters:

string   $path   —  Path to use

[ Top ]

addDir   [line 384]

void addDir( string $path)

Internal function which iterates through directories and subdirectories, using _addFile for each file it finds.
  • Access: protected

Parameters:

string   $path   —  path to the directory

[ Top ]

addFile   [line 315]

mixed addFile( string $file)

Internal function which generates metainfo data for a file
  • Return: false on failure or file metainfo data
  • Throws: File_Bittorrent2_Exception if given file cannot be opened
  • Access: protected

Parameters:

string   $file   —  path to the file

[ Top ]

addFiles   [line 512]

bool addFiles( array $filelist, string $dir)

Function to add a specific list of files, pass blank to the constructor then call this function

Parameters:

array   $filelist   —  list of filepaths to add;
string   $dir   —  folder containing files

[ Top ]

buildTorrent   [line 244]

mixed buildTorrent( [array $metainfo = array()])

Function to build the .torrent file based on the parameters you have set with the set* functions.
  • Return: false on failure or a string containing the metainfo
  • Throws: File_Bittorrent2_Exception if no file or directory is given

Parameters:

array   $metainfo   —  custom data set to be included in the metainfo

[ Top ]

closeFile   [line 482]

void closeFile( )

Internal function to close a file pointer
  • Access: protected

[ Top ]

dirList   [line 413]

array dirList( string $dir)

Internal function which recurses through subdirectory and returns an array of file paths
  • Return: file list
  • Access: protected

Parameters:

string   $dir   —  path to the directory

[ Top ]

encodeTorrent   [line 276]

string encodeTorrent( [array $info = array()], [array $metainfo = array()])

Internal function which bencodes the data into a valid torrent metainfo string
  • Return: bencoded metainfo
  • Throws: File_Bittorrent2_Exception if no file or directory is defined
  • Access: protected

Parameters:

array   $info   —  file data
array   $metainfo   —  custom data set to be included in the metainfo

[ Top ]

filesize   [line 443]

int filesize( string $file)

Internal function to get the filesize of a file. Workaround for files >2GB.
  • Return: the filesize
  • Access: protected

Parameters:

string   $file   —  path to the file

[ Top ]

openFile   [line 461]

bool openFile( string $file)

Internal function to open a file.

Workaround for files >2GB using popen

  • Throws: File_Bittorrent2_Exception if opening file fails or is larger than 2GB (on Windows only)
  • Access: protected

Parameters:

string   $file   —  path to the file

[ Top ]

setAnnounce   [line 162]

bool setAnnounce( string $announce)

Function to set the announce URL for the .torrent file

Parameters:

string   $announce   —  announce url

[ Top ]

setAnnounceList   [line 175]

bool setAnnounceList( array $announce_list)

Function to set the announce list for the .torrent file

Parameters:

array   $announce_list   —  announce list

[ Top ]

setComment   [line 188]

bool setComment( string $comment)

Function to set the comment for the .torrent file

Parameters:

string   $comment   —  comment

[ Top ]

setIsPrivate   [line 558]

void setIsPrivate( bool $bool)

Sets whether the torrent is marked as 'private'

Taken from http://www.azureuswiki.com/index.php/Secure_Torrents

Tracker sites wanting to ensure that [clients] only obtains peers directly from the tracker itself (besides incoming connections) should embed the key "private" with the value "1" inside the "info" dict of the .torrent file:

  1. infod6:lengthi136547e4:name6:a............7:privatei1ee

This new field will be ignored by [older] clients, so it does not break compatibility as long as they've properly implemented the BT spec. Also, this new field WILL change the torrent's infohash, which means that torrents made without the secure flag aren't compatible with torrents made with it. If you update all the torrents on your web site, you will have to ask users to re-download the torrent files in order to let them connect to your tracker.

  • Access: public

Parameters:

bool   $bool   — 

[ Top ]

setName   [line 498]

bool setName( string $name)

Function to set the name for the .torrent file

Parameters:

string   $name   —  name

[ Top ]

setPath   [line 202]

bool setPath( string $path)

Function to set the path for the file/dir to make the .torrent for Can also be set through the constructor.

Parameters:

string   $path   —  path to file/dir

[ Top ]

setPieceLength   [line 226]

bool setPieceLength( int $piece_length)

Function to set the piece length for the .torrent file.

min: 32 (32KB), max: 4096 (4MB)

  • Throws: File_Bittorrent2_Exception if piece length is invalid

Parameters:

int   $piece_length   —  piece length in kilobytes

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:31:15 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.