Changeset 130

Show
Ignore:
Timestamp:
01/20/07 23:23:46 (2 years ago)
Author:
mikey
Message:

changed binary format to use of strings only to be cross-platform compatible (original used integer has machine dependent size and byte order, therefore it would probably be restored as completely different value on another platform)
bugfix: do not fseek() to COMPILER_HALT_OFFSET if not in same archive as where StarLoader? is in

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/star/StarArchive.php

    r118 r130  
    103103        } 
    104104         
    105         $this->writer->write(pack('a4c1i1a247', 
     105        $ids = array_keys($this->index); 
     106        $this->writer->write(pack('a4c1a8a243', 
    106107                                  'star', 
    107108                                  self::VERSION, 
    108                                   sizeof(array_keys($this->index)), 
     109                                  (string) count($ids), 
    109110                                  "\0" 
    110111                             ) 
     
    112113         
    113114        // write index 
    114         foreach (array_keys($this->index) as $id) { 
    115             $this->writer->write(pack('a80a80a80i1i1a8', 
     115        foreach ($ids as $id) { 
     116            $this->writer->write(pack('a80a72a80a8a8a8', 
    116117                                      $id, 
    117118                                      $this->index[$id]['basename'], 
    118119                                      $this->index[$id]['path'], 
    119                                       $this->index[$id]['datasize'], 
    120                                       $offset, 
     120                                      (string) $this->index[$id]['datasize'], 
     121                                      (string) $offset, 
    121122                                      "\0" 
    122123                                 ) 
     
    126127         
    127128        // write index 
    128         foreach (array_keys($this->index) as $id) { 
     129        foreach ($ids as $id) { 
    129130            $this->writer->write($this->index[$id]['payload']); 
    130131        } 
  • trunk/src/main/php/net/stubbles/star/StarLoader.php

    r94 r130  
    4343     * @param   string  $archive  archive to retrieve index for 
    4444     * @return  array 
     45     * @throws  StarException 
    4546     */ 
    4647    public static function acquire($archive) 
    4748    { 
    4849        static $archives = array(); 
     50        if (file_exists($archive) == false) { 
     51            return array(); 
     52        } 
     53         
    4954        if (isset($archives[$archive]) == false) { 
    5055            $archives[$archive] = array(); 
     
    5257         
    5358            $current['handle']  = fopen($archive, 'rb'); 
    54             if (defined('__COMPILER_HALT_OFFSET__') == true) { 
     59            if (__FILE__ == $archive && defined('__COMPILER_HALT_OFFSET__') == true) { 
    5560                fseek($current['handle'], __COMPILER_HALT_OFFSET__); 
    5661            } else { 
     
    5863            } 
    5964             
    60             $header = @unpack('a4id/c1version/i1indexsize/a*reserved', fread($current['handle'], 0x0100)); 
     65            $header = unpack('a4id/c1version/a8indexsize/a*reserved', fread($current['handle'], 0x0100)); 
    6166            if (false === $header) { 
    6267                // invalid star file 
     
    6469            } 
    6570             
    66             for ($current['index'] = array(), $i = 0; $i < $header['indexsize']; $i++) { 
    67                 $entry = unpack('a80id/a80filename/a80path/i1size/i1offset/a*reserved', 
     71            $current['index'] = array(); 
     72            for ($i = 0; $i < $header['indexsize']; $i++) { 
     73                $entry = unpack('a80id/a72filename/a80path/a8size/a8offset/a*reserved', 
    6874                                fread($current['handle'], 0x0100) 
    6975                ); 
    7076                 
    71                 $current['index'][$entry['id']]= array('size' => $entry['size'], 'offset' => $entry['offset']); 
     77                $current['index'][$entry['id']]= array('size' => (int) $entry['size'], 'offset' => (int) $entry['offset']); 
    7278            } 
    7379        }