Example #1
0
 /**
  * Reads a block of the physical file that the torrent represents.
  *
  * @param integer $piece_index Index of the piece containing the block.
  * @param integer $block_begin Beginning of the block relative to the piece in byets.
  * @param integer $length Length of the block in bytes.
  * @return string
  */
 public function readBlock($piece_index, $block_begin, $length)
 {
     if ($piece_index > ceil($this->__get('length') / $this->size_piece) - 1) {
         throw new PHPTracker_Error('Invalid piece index: ' . $piece_index);
     }
     if ($block_begin + $length > $this->size_piece) {
         throw new PHPTracker_Error('Invalid block boundary: ' . $block_begin . ', ' . $length);
     }
     return $this->file->readBlock($piece_index * $this->size_piece + $block_begin, $length);
 }
 public function testReadBlock()
 {
     $this->assertEquals(substr(self::TEST_DATA, 2, 2), $this->object->readBlock(2, 2));
 }