Changeset 47 for trunk

Show
Ignore:
Timestamp:
19.10.2005 18:38:25 (3 years ago)
Author:
m
Message:

Closes #6. Enhances File_Bittorrent_Decode::decodeFile() filename handling

Location:
trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/File/Bittorrent/Decode.php

    r42 r47  
    189189        $this->_source_length = strlen($this->_source); 
    190190        $decoded = $this->_bdecode(); 
     191        if (!is_array($decoded)) { 
     192            PEAR::raiseError('File_Bittorrent_Decode::decode() - Corrupted bencoded data.', null, null, "Failed to decode data from file '$file'."); 
     193            return false; 
     194        } 
    191195 
    192196        // Compute info_hash 
     
    224228                ); 
    225229            } 
     230        // In case the torrent contains only on file 
     231        } elseif(isset($decoded['info']['name']))  { 
     232                $this->files[] = array( 
     233                   'filename' => $decoded['info']['name'], 
     234                   'size'     => $decoded['info']['length'], 
     235                ); 
    226236        } 
    227237        // If the the info->length field is present we are dealing with 
  • trunk/torrentinfo.php

    r42 r47  
    3737    require_once 'Console/Getargs.php'; 
    3838 
     39    // Set error handling 
     40    PEAR::setErrorHandling(PEAR_ERROR_PRINT); 
     41 
    3942    // Get filename from command line 
    4043    $args_config = array( 
     
    6467        switch($key) { 
    6568        case 'files': 
    66             echo "\n"; 
     69            $n = 1; 
     70            $files_n = count($val); 
     71            $n_length = strlen($files_n); 
     72            echo '(' . $files_n . ")\n"; 
    6773            foreach ($val as $file) { 
    68                 echo str_repeat(' ', 20) . '- ' . $file['filename'] . "\n"; 
     74                echo str_repeat(' ', 20) . '' . str_pad($n, $n_length, ' ', PAD_LEFT) . ': ' . $file['filename'] . "\n"; 
     75                $n++; 
    6976            } 
    7077            break;