Changeset 1622

Show
Ignore:
Timestamp:
06/12/08 13:52:26 (4 months ago)
Author:
mikey
Message:

deliver correct file length for files opened with compression streams

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/streams/stubFileInputStream.php

    r1605 r1622  
    1919{ 
    2020    /** 
     21     * name of the file 
     22     * 
     23     * @var  string 
     24     */ 
     25    protected $fileName; 
     26 
     27    /** 
    2128     * constructor 
    2229     * 
     
    2734    { 
    2835        if (is_string($file) === true) { 
    29             $fp = fopen($file, $mode); 
     36            $fp             = fopen($file, $mode); 
     37            $this->fileName = $file; 
    3038        } elseif (is_resource($file) === true) { 
    3139            $fp = $file; 
     
    4452        $this->close(); 
    4553    } 
     54 
     55    /** 
     56     * helper method to retrieve the length of the resource 
     57     * 
     58     * Not all stream wrappers support (f)stat - the extending class then 
     59     * needs to take care to deliver the correct resource length then. 
     60     * 
     61     * @return  int 
     62     */ 
     63    protected function getResourceLength() 
     64    { 
     65        if (null === $this->fileName) { 
     66            return parent::getResourceLength(); 
     67        } 
     68         
     69        if (substr($this->fileName, 0, 16) === 'compress.zlib://') { 
     70            return filesize(substr($this->fileName, 16)); 
     71        } elseif (substr($this->fileName, 0, 17) === 'compress.bzip2://') { 
     72            return filesize(substr($this->fileName, 17)); 
     73        } 
     74    } 
    4675} 
    4776?> 
  • trunk/src/main/php/net/stubbles/streams/stubResourceInputStream.php

    r1552 r1622  
    103103        } 
    104104         
     105        return $this->getResourceLength() - $bytesRead; 
     106    } 
     107 
     108    /** 
     109     * helper method to retrieve the length of the resource 
     110     * 
     111     * Not all stream wrappers support (f)stat - the extending class then 
     112     * needs to take care to deliver the correct resource length then. 
     113     * 
     114     * @return  int 
     115     */ 
     116    protected function getResourceLength() 
     117    { 
    105118        $fileData = fstat($this->handle); 
    106         return $fileData['size'] - $bytesRead
     119        return $fileData['size']
    107120    } 
    108121