ParagonIE\Halite\Stream\MutableFile::readBytes PHP Method

readBytes() public method

Read from a stream; prevent partial reads
public readBytes ( integer $num, boolean $skipTests = false ) : string
$num integer
$skipTests boolean
return string
    public function readBytes(int $num, bool $skipTests = false) : string
    {
        if ($num < 0) {
            throw new CryptoException\CannotPerformOperation('num < 0');
        } elseif ($num === 0) {
            return '';
        }
        if ($this->pos + $num > $this->stat['size']) {
            throw new CryptoException\CannotPerformOperation('Out-of-bounds read');
        }
        $buf = '';
        $remaining = $num;
        do {
            if ($remaining <= 0) {
                break;
            }
            $read = \fread($this->fp, $remaining);
            if ($read === false) {
                throw new CryptoException\FileAccessDenied('Could not read from the file');
            }
            $buf .= $read;
            $readSize = CryptoUtil::safeStrlen($read);
            $this->pos += $readSize;
            $remaining -= $readSize;
        } while ($remaining > 0);
        return $buf;
    }