mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2026-02-24 18:12:03 +00:00
19 lines
492 B
TypeScript
19 lines
492 B
TypeScript
export class LineBreakTransformer {
|
|
private chunks = "";
|
|
|
|
// noinspection JSUnusedGlobalSymbols
|
|
transform(chunk: string, controller: TransformStreamDefaultController) {
|
|
this.chunks += chunk;
|
|
const lines = this.chunks.split("\r\n");
|
|
this.chunks = lines.pop()!;
|
|
for (const line of lines) {
|
|
controller.enqueue(line);
|
|
}
|
|
}
|
|
|
|
// noinspection JSUnusedGlobalSymbols
|
|
flush(controller: TransformStreamDefaultController) {
|
|
controller.enqueue(this.chunks);
|
|
}
|
|
}
|