Swift_ByteStream_FileByteStream::read PHP 메소드

read() 공개 메소드

If less bytes exist than are requested the remaining bytes are given instead. If no bytes are remaining at all, boolean false is returned.
public read ( integer $length ) : string | boolean
$length integer
리턴 string | boolean
    public function read($length)
    {
        $fp = $this->_getReadHandle();
        if (!feof($fp)) {
            if ($this->_quotes) {
                ini_set('magic_quotes_runtime', 0);
            }
            $bytes = fread($fp, $length);
            if ($this->_quotes) {
                ini_set('magic_quotes_runtime', 1);
            }
            $this->_offset = ftell($fp);
            // If we read one byte after reaching the end of the file
            // feof() will return false and an empty string is returned
            if ($bytes === '' && feof($fp)) {
                $this->_resetReadHandle();
                return false;
            }
            return $bytes;
        }
        $this->_resetReadHandle();
        return false;
    }

Usage Example

 /**
  * @test
  * @expectedException \Swift_IoException
  */
 public function shouldThrowExceptionOnConsecutiveRead()
 {
     $fbs = new \Swift_ByteStream_FileByteStream('does not exist');
     try {
         $fbs->read(100);
     } catch (\Swift_IoException $exc) {
         $fbs->read(100);
     }
 }