public async function readUntilAsync()

in src/io/BufferedReader.php [102:126]


  public async function readUntilAsync(string $suffix): Awaitable<?string> {
    $buf = $this->buffer;
    $idx = Str\search($buf, $suffix);
    $suffix_len = Str\length($suffix);
    if ($idx !== null) {
      $this->buffer = Str\slice($buf, $idx + $suffix_len);
      return Str\slice($buf, 0, $idx);
    }

    do {
      // + 1 as it would have been matched in the previous iteration if it
      // fully fit in the chunk
      $offset = Math\maxva(0, Str\length($buf) - $suffix_len + 1);
      $chunk = await $this->handle->readAllowPartialSuccessAsync();
      if ($chunk === '') {
        $this->buffer = $buf;
        return null;
      }
      $buf .= $chunk;
      $idx = Str\search($buf, $suffix, $offset);
    } while ($idx === null);

    $this->buffer = Str\slice($buf, $idx + $suffix_len);
    return Str\slice($buf, 0, $idx);
  }