HttpMultipartParser.RebufferableBinaryReader.ReadByteLine C# (CSharp) Method

ReadByteLine() public method

Reads a series of bytes delimited by the byte encoding of newline for this platform. the newline bytes will not be included in the return data.
public ReadByteLine ( ) : byte[]
return byte[]
        public byte[] ReadByteLine()
        {
            var builder = new MemoryStream();
            while (true)
            {
                if (!streamStack.HasData())
                {
                    if (StreamData() == 0)
                    {
                        return builder.Length > 0 ? builder.ToArray() : null;
                    }
                }

                bool hitStreamEnd;
                byte[] line = streamStack.ReadByteLine(out hitStreamEnd);

                builder.Write(line, 0, line.Length);
                if (!hitStreamEnd)
                {
                    return builder.ToArray();
                }
            }
        }

Usage Example

        public void CanReadByteLineOnMixedAsciiAndUTF8Text()
        {
            var reader = new RebufferableBinaryReader(TestUtil.StringToStreamNoBom("Bonjour poignée"), Encoding.UTF8);
            byte[] bytes = reader.ReadByteLine();
            var expected = new byte[] {66, 111, 110, 106, 111, 117, 114, 32, 112, 111, 105, 103, 110, 195, 169, 101};

            foreach (var pair in expected.Zip(bytes, Tuple.Create))
            {
                Assert.AreEqual(pair.Item1, pair.Item2);
            }
        }
All Usage Examples Of HttpMultipartParser.RebufferableBinaryReader::ReadByteLine