protected function fieldsRemain()
    {
        $bufferlen = strlen($this->buffer);
        $minlen = strlen($this->lastBoundary);

        # if the buffer is too short to contain the last boundary
        # read enough bytes into the buffer to allow for a strpos test
        if ($bufferlen < $minlen) {
            if (feof($this->fp)) {
                fclose($this->fp);
                throw new \sndsgd\http\data\DecodeException(
                    "Invalid multipart data encountered; ".
                    "end of content was reached before expected"
                );
            }

            $bytes = fread($this->fp, $this->bytesPerRead);
            if ($bytes === false) {
                fclose($this->fp);
                throw new \RuntimeException(
                    "failed to read $minlen bytes from input stream"
                );
            }

            $this->buffer .= $bytes;
        }

        # if the buffer starts with the last boundary, there are no more fields
        return (strpos($this->buffer, $this->lastBoundary) !== 0);
    }