Chore: update build infra & performance improvements

This commit is contained in:
SukkaW
2023-11-29 21:50:10 +08:00
parent f14a604264
commit 34c67e5a0d
8 changed files with 146 additions and 29 deletions

View File

@@ -19,14 +19,15 @@ interface TextLineStreamOptions {
* ```
*/
export class TextLineStream extends TransformStream<string, string> {
private __buf = '';
// private __buf = '';
constructor(options?: TextLineStreamOptions) {
const allowCR = options?.allowCR ?? false;
let __buf = '';
super({
transform: (chunk, controller) => {
chunk = this.__buf + chunk;
transform(chunk, controller) {
chunk = __buf + chunk;
for (; ;) {
const lfIndex = chunk.indexOf('\n');
@@ -57,14 +58,14 @@ export class TextLineStream extends TransformStream<string, string> {
break;
}
this.__buf = chunk;
__buf = chunk;
},
flush: (controller) => {
if (this.__buf.length > 0) {
if (allowCR && this.__buf[this.__buf.length - 1] === '\r') {
controller.enqueue(this.__buf.slice(0, -1));
flush(controller) {
if (__buf.length > 0) {
if (allowCR && __buf[__buf.length - 1] === '\r') {
controller.enqueue(__buf.slice(0, -1));
} else {
controller.enqueue(this.__buf);
controller.enqueue(__buf);
};
}
},