Example #1
0
        async Task <string> ReadLineAsync(bool doAsync, CancellationToken cancellationToken)
        {
            if (stream == null)
            {
                throw new InvalidOperationException();
            }

            using (var builder = new ByteArrayBuilder(64)) {
                bool complete;

                do
                {
                    if (doAsync)
                    {
                        complete = await stream.ReadLineAsync(builder, cancellationToken).ConfigureAwait(false);
                    }
                    else
                    {
                        complete = stream.ReadLine(builder, cancellationToken);
                    }
                } while (!complete);

                // FIXME: All callers expect CRLF to be trimmed, but many also want all trailing whitespace trimmed.
                builder.TrimNewLine();

                return(builder.ToString());
            }
        }