|
@@ -25,23 +25,25 @@ export class TextLineStream extends TransformStream<string, string> {
|
|
|
allowCR = false
|
|
allowCR = false
|
|
|
}: TextLineStreamOptions = {}) {
|
|
}: TextLineStreamOptions = {}) {
|
|
|
let __buf = '';
|
|
let __buf = '';
|
|
|
|
|
+ let chunkIndex = 0;
|
|
|
|
|
|
|
|
super({
|
|
super({
|
|
|
transform(chunk, controller) {
|
|
transform(chunk, controller) {
|
|
|
chunk = __buf + chunk;
|
|
chunk = __buf + chunk;
|
|
|
|
|
+ chunkIndex = 0;
|
|
|
|
|
|
|
|
for (; ;) {
|
|
for (; ;) {
|
|
|
- const lfIndex = chunk.indexOf('\n');
|
|
|
|
|
|
|
+ const lfIndex = chunk.indexOf('\n', chunkIndex);
|
|
|
|
|
|
|
|
if (allowCR) {
|
|
if (allowCR) {
|
|
|
- const crIndex = chunk.indexOf('\r');
|
|
|
|
|
|
|
+ const crIndex = chunk.indexOf('\r', chunkIndex);
|
|
|
|
|
|
|
|
if (
|
|
if (
|
|
|
crIndex !== -1 && crIndex !== (chunk.length - 1)
|
|
crIndex !== -1 && crIndex !== (chunk.length - 1)
|
|
|
&& (lfIndex === -1 || (lfIndex - 1) > crIndex)
|
|
&& (lfIndex === -1 || (lfIndex - 1) > crIndex)
|
|
|
) {
|
|
) {
|
|
|
- controller.enqueue(chunk.slice(0, crIndex));
|
|
|
|
|
- chunk = chunk.slice(crIndex + 1);
|
|
|
|
|
|
|
+ controller.enqueue(chunk.slice(chunkIndex, crIndex));
|
|
|
|
|
+ chunkIndex = crIndex + 1;
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -51,15 +53,15 @@ export class TextLineStream extends TransformStream<string, string> {
|
|
|
if (chunk[lfIndex - 1] === '\r') {
|
|
if (chunk[lfIndex - 1] === '\r') {
|
|
|
crOrLfIndex--;
|
|
crOrLfIndex--;
|
|
|
}
|
|
}
|
|
|
- controller.enqueue(chunk.slice(0, crOrLfIndex));
|
|
|
|
|
- chunk = chunk.slice(lfIndex + 1);
|
|
|
|
|
|
|
+ controller.enqueue(chunk.slice(chunkIndex, crOrLfIndex));
|
|
|
|
|
+ chunkIndex = lfIndex + 1;
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- __buf = chunk;
|
|
|
|
|
|
|
+ __buf = chunk.slice(chunkIndex);
|
|
|
},
|
|
},
|
|
|
flush(controller) {
|
|
flush(controller) {
|
|
|
if (__buf.length > 0) {
|
|
if (__buf.length > 0) {
|