Handle chunks containing multiple EOL (#6146)
Credit to @EEParker a169dd6d39 (diff-6d394759c0a824a137b47986d0cce571R158)
Co-Authored-By: Jeff Parker, PE <eeparker@users.noreply.github.com>
This commit is contained in:
parent
fb5da88b25
commit
0ae689c8a8
|
|
@ -89,17 +89,23 @@ namespace Microsoft.AspNetCore.NodeServices.Util
|
|||
|
||||
OnChunk(new ArraySegment<char>(buf, 0, chunkLength));
|
||||
|
||||
var lineBreakPos = Array.IndexOf(buf, '\n', 0, chunkLength);
|
||||
if (lineBreakPos < 0)
|
||||
int lineBreakPos = -1;
|
||||
int startPos = 0;
|
||||
|
||||
// get all the newlines
|
||||
while ((lineBreakPos = Array.IndexOf(buf, '\n', startPos, chunkLength - startPos)) >= 0 && startPos < chunkLength)
|
||||
{
|
||||
_linesBuffer.Append(buf, 0, chunkLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
_linesBuffer.Append(buf, 0, lineBreakPos + 1);
|
||||
var length = (lineBreakPos + 1) - startPos;
|
||||
_linesBuffer.Append(buf, startPos, length);
|
||||
OnCompleteLine(_linesBuffer.ToString());
|
||||
_linesBuffer.Clear();
|
||||
_linesBuffer.Append(buf, lineBreakPos + 1, chunkLength - (lineBreakPos + 1));
|
||||
startPos = lineBreakPos + 1;
|
||||
}
|
||||
|
||||
// get the rest
|
||||
if (lineBreakPos < 0 && startPos < chunkLength)
|
||||
{
|
||||
_linesBuffer.Append(buf, startPos, chunkLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue