UNPKG

573 BJavaScriptView Raw
1export class LineBreakTransformer {
2 constructor() {
3 this.chunks = "";
4 }
5 transform(chunk, controller) {
6 // Append new chunks to existing chunks.
7 this.chunks += chunk;
8 // For each line breaks in chunks, send the parsed lines out.
9 const lines = this.chunks.split("\r\n");
10 this.chunks = lines.pop();
11 lines.forEach((line) => controller.enqueue(line + "\r\n"));
12 }
13 flush(controller) {
14 // When the stream is closed, flush any remaining chunks out.
15 controller.enqueue(this.chunks);
16 }
17}