code: private static function readFully($inStream, $numBytes)
      {
          Checker::argNat("numBytes", $numBytes);
  
          $full = '';
          $bytesRemaining = $numBytes;
          while (!feof($inStream) && $bytesRemaining > 0) {
              $part = fread($inStream, $bytesRemaining);
              if ($part === false) throw new StreamReadException("Error reading from \$inStream.");
              $full .= $part;
              $bytesRemaining -= strlen($part);
          }
          return $full;
      }
docs: Sometimes fread() returns less than the request number of bytes (for example, when reading
  from network streams).  This function repeatedly calls fread until the requested number of
  bytes have been read or we've reached EOF.
  
  @param resource $inStream
  @param int $numBytes
  @throws StreamReadException
  @return string