Reads the number of bytes from the file.

@param integer $bytes The number of bytes.

@return string The binary string read.

@throws RuntimeException If the read fails.
195407
private function read($bytes)
    {
        $read = '';
        $total = $bytes;

        while (!feof($this->handle) && $bytes) {
            if (false === ($chunk = fread($this->handle, $bytes))) {
                throw new RuntimeException(
                    sprintf(
                        'Could not read %d bytes from "%s".',
                        $bytes,
                        $this->file
                    )
                );
            }

            $read .= $chunk;
            $bytes -= strlen($chunk);
        }

        if (($actual = strlen($read)) !== $total) {
            throw new RuntimeException(
                sprintf(
                    'Only read %d of %d in "%s".',
                    $actual,
                    $total,
                    $this->file
                )
            );
        }

        return $read;
    }
72734
public function read($length)
    {
        // let Guzzle decide what to do.
        if ($length <= 0 || $this->eof()) {
            return $this->stream->read($length);
        }
        $count = 0;
        $bytes = '';
        while ($count < $length) {
            $nRead = $this->readRawDecodeAndAppend($length - $count, $bytes);
            if ($nRead === -1) {
                break;
            }
            $this->position += $nRead;
            $count += $nRead;
        }
        return $bytes;
    }
352473
public function read($bytes)
    {
        $read = 0;
        $parts = array();

        while ($read < $bytes) {
            $data = fread($this->socket, $bytes - $read);

            if ($data === false) {
                // server must have dropped the connection
                if (feof($this->socket)) {
                    $this->close();
                }

                return false;
            }

            $read += strlen($data);
            $parts[] = $data;
        }

        return implode($parts);
    }
546225
public function read($bytes)
    {
        $content = $this->file->data();

        $return = substr($content, $this->position(), $bytes);

        $newPosition = $this->position()+$bytes;

        $newPosition = $newPosition > strlen($content) ? strlen($content) : $newPosition;

        $this->position($newPosition);
        $this->file->setAccessTime(time());

        return $return;
    }
1012027
public function read($length)
    {
        if ($this->isOpen() === false) {
            $msg = "Cannot read from a closed MemoryStream.";
            throw new MemoryStreamAccess($msg, $this, MemoryStreamException::NOT_OPEN);
        }
        
        if ($length === 0) {
            return '';
        }

        $position = $this->position;
        $finalPosition = $position + $length;

        if ($finalPosition > $this->length) {
            $msg = "Cannot read outside the bounds of the MemoryStream.";
            throw new MemoryStreamException($msg, $this, MemoryStreamException::READ);
        }

        $this->incrementPosition($length);

        $returnValue = '';

        while ($position < $finalPosition) {
            $returnValue .= $this->binary[$position];
            $position++;
        }

        return $returnValue;
    }
99902
public function gets($length = 0)
	{
		if (!$this->fh)
		{
			throw new \RuntimeException('File not open');
		}

		// Capture PHP errors
		$php_errormsg = 'Error Unknown';
		$track_errors = ini_get('track_errors');
		ini_set('track_errors', true);

		switch ($this->processingmethod)
		{
			case 'gz':
				$res = $length ? gzgets($this->fh, $length) : gzgets($this->fh);
				break;

			case 'bz':
			case 'f':
			default:
				$res = $length ? fgets($this->fh, $length) : fgets($this->fh);
				break;
		}

		if (!$res)
		{
			throw new \RuntimeException($php_errormsg);
		}

		// Restore error tracking to what it was before
		ini_set('track_errors', $track_errors);

		// Return the result
		return $res;
	}
1194011
function read($inByte = null)
    {
        $this->_assertReadable();

        $inByte = ($inByte === null)
            ?
            (
                ($this->getBuffer() === null) ? -1 : $this->getBuffer()
            )
            : $inByte;

        $stream = $this->resource()->getRHandler();
        $data   = stream_get_contents($stream, $inByte);
        if (false === $data)
            throw new \RuntimeException('Cannot read stream.');

        if (function_exists('mb_strlen'))
            $transCount = mb_strlen($data, '8bit');
        else
            $transCount = strlen($data);

        $this->_resetTransCount($transCount);

        return $data;
    }
56945
private function read($bytes)
    {
        if (false === ($read = @fread($this->handle(), $bytes))) {
            throw FileException::lastError();
        }

        if (($actual = strlen($read)) !== $bytes) {
            throw FileException::create(
                'Only read %d of %d bytes from "%s".',
                $actual,
                $bytes,
                $this->file
            );
        }

        return $read;
    }
903535
public function read($bytes=0)
    {
        // If the connection wrote into the resource the handle will be placed
        // at the end and nothing will be returned
        if ($this->didWrite) {
            $this->stream = null;
        }

        if (!$bytes) {
            return $this->stream()->toString();
        }

        $stream = $this->stream();
        $stream->setChunkSize($bytes);

        if (!$stream->isOpen()) {
            $stream->rewind();
        } else {
            $stream->next();
        }

        return $stream->current();
    }
100426
public static function getStrongPseudoRandomBytes(int $length): string {
        $result = openssl_random_pseudo_bytes($length, $strong);
        if(!$strong) {
            throw new RuntimeException('Not strong enough');
        }
        return $result;
    }
1053977
public static function bytesToString($bytes) {
    $units = array_map('t', ['bytes', 'KB', 'MB', 'GB', 'TB']);

    while ($bytes > 1024) {
      $bytes /= 1024;
      array_shift($units);
    }
    return $bytes . ' ' . reset($units);
  }
560898
protected function randomBytes($bytes = 32)
    {
        if (extension_loaded('openssl')) {
            return openssl_random_pseudo_bytes($bytes);
        } elseif (extension_loaded('mcrypt')) {
            return mcrypt_create_iv($bytes, MCRYPT_DEV_URANDOM);
        }

        throw new RuntimeException('Extension "openssl" or "mcrypt" is required, but is not installed.');
    }
1147723
protected function formatBytes($bytes)
    {
        $bytes = (int) $bytes;

        if ($bytes > 1024 * 1024) {
            return round($bytes / 1024 / 1024, 2) . ' MB';
        }

        if ($bytes > 1024) {
            return round($bytes / 1024, 2) . ' KB';
        }

        return $bytes . ' B';
    }
100350
protected function readBytes($bytes)
    {
        $data = '';
        $len  = 0;

        while ($len < $bytes && !$this->eof()) {
            $d = fread($this->fp, $bytes-$len);
            if ($this->debug) {
                $this->debug('S: '. $d);
            }
            $data .= $d;
            $data_len = strlen($data);
            if ($len == $data_len) {
                break; // nothing was read -> exit to avoid apache lockups
            }
            $len = $data_len;
        }

        return $data;
    }
1333533
public function write(string $bytes): int
    {
        return $this->outputStream->write(iconv('UTF-8', $this->charset, $bytes));
    }
487028
public function write(string $bytes): int
    {
        if ($this->isFileCreationDelayed()) {
            $this->setHandle($this->openFile($this->file, $this->mode));
        }

        return parent::write($bytes);
    }
82976
public function read($bytes)
    {
        $data = substr($this->str, $this->pos, $bytes);

        $this->seekto($this->pos + $bytes);

        return $data;
    }