english/libraries/joomla/filesystem/stream.php
/**
	 * Read a file
	 *
	 * Handles user space streams appropriately otherwise any read will return 8192
	 *
	 * @param   integer  $length	Length of data to read
	 *
	 * @return  mixed
	 *
	 * @see     http://php.net/manual/en/function.fread.php
	 * @since   11.1
	 */
Read a file
Handles user space streams appropriately otherwise any read will return 8192

@param   integer  $length    Length of data to read

@return  mixed


Read a file Handles user space streams appropriately otherwise any read will return 8192 @param integer $length Length of data to read @return mixed
function read($length=0)
	{
		if (!$this->_filesize && !$length) {
			$this->filesize();
			if (!$this->_filesize) {
				$length = -1;
			}
			else {
				$length = $this->_filesize;
			}
		}
		if (!$this->_fh) {
			$this->setError(JText::_('JLIB_FILESYSTEM_ERROR_STREAMS_FILE_NOT_OPEN'));
			return false;
		}
		$retval = false;
		$php_errormsg = 'Error Unknown';
		$track_errors = ini_get('track_errors');
		ini_set('track_errors', true);
		$remaining = $length;
		do
		{
			switch($this->processingmethod)
			{
				case 'bz':
					$res = ($remaining > 0) ? bzread($this->_fh, $remaining) : bzread($this->_fh, $this->chunksize);
					break;
				case 'gz':
					$res = ($remaining > 0) ? gzread($this->_fh, $remaining) : gzread($this->_fh, $this->chunksize);
					break;
				case 'f':
				default:
					$res = ($remaining > 0) ? fread($this->_fh, $remaining) : fread($this->_fh, $this->chunksize);
					break;
			}
			if (!$res) {
				$this->setError($php_errormsg);
				$remaining = 0; 
			}
			else {
				if (!$retval) {
					$retval = '';
				}
				$retval .= $res;
				if (!$this->eof()) {
					$len = strlen($res);
					$remaining -= $len;
				}
				else {
					$remaining = 0;
					$length = strlen($retval);
				}
			}
		}
		while($remaining || !$length);
		ini_set('track_errors', $track_errors);
		return $retval;
	}
function read ( $ length = 0 ) { if ( ! $ this -> _filesize && ! $ length ) { $ this -> filesize ( ) ; if ( ! $ this -> _filesize ) { $ length = - 1 ; } else { $ length = $ this -> _filesize ; } } if ( ! $ this -> _fh ) { $ this -> setError ( JText :: _ ( 'JLIB_FILESYSTEM_ERROR_STREAMS_FILE_NOT_OPEN' ) ) ; return false ; } $ retval = false ; $ php_errormsg = 'Error Unknown' ; $ track_errors = ini_get ( 'track_errors' ) ; ini_set ( 'track_errors' , true ) ; $ remaining = $ length ; do { switch ( $ this -> processingmethod ) { case 'bz' : $ res = ( $ remaining > 0 ) ? bzread ( $ this -> _fh , $ remaining ) : bzread ( $ this -> _fh , $ this -> chunksize ) ; break ; case 'gz' : $ res = ( $ remaining > 0 ) ? gzread ( $ this -> _fh , $ remaining ) : gzread ( $ this -> _fh , $ this -> chunksize ) ; break ; case 'f' : default : $ res = ( $ remaining > 0 ) ? fread ( $ this -> _fh , $ remaining ) : fread ( $ this -> _fh , $ this -> chunksize ) ; break ; } if ( ! $ res ) { $ this -> setError ( $ php_errormsg ) ; $ remaining = 0 ; } else { if ( ! $ retval ) { $ retval = '' ; } $ retval .= $ res ; if ( ! $ this -> eof ( ) ) { $ len = strlen ( $ res ) ; $ remaining -= $ len ; } else { $ remaining = 0 ; $ length = strlen ( $ retval ) ; } } } while ( $ remaining || ! $ length ) ; ini_set ( 'track_errors' , $ track_errors ) ; return $ retval ; }
Read a file
 Handles user space streams appropriately otherwise any read will return 8192
Read a file Handles user space streams appropriately otherwise any read will return 8192
// Get the filesize // Set it to the biggest and then wait until eof // Capture PHP errors // Do chunked reads where relevant // jump from the loop // If it's the end of the file then we've nothing left to read; reset remaining and len // Restore error tracking to what it was before // Return the result