@meetquinn/animactl 0.1.35-canary.797.1.4b8d660 → 0.1.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,12 @@
1
+ /**
2
+ * Splits a byte stream into lines. Only each new chunk is searched for a line
3
+ * break, and the pieces of a partial line are joined once, when its break
4
+ * arrives. Re-splitting the whole pending text on every chunk made a long line
5
+ * quadratic: a multi-megabyte line from a provider CLI kept the event loop busy
6
+ * for minutes.
7
+ */
1
8
  export declare class LineBuffer {
2
- private text;
9
+ private pending;
3
10
  accept(chunk: string): string[];
4
11
  }
5
12
  //# sourceMappingURL=line-buffer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"line-buffer.d.ts","sourceRoot":"","sources":["../../../server/providers/line-buffer.ts"],"names":[],"mappings":"AAAA,qBAAa,UAAU;IACrB,OAAO,CAAC,IAAI,CAAM;IAElB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE;CAMhC"}
1
+ {"version":3,"file":"line-buffer.d.ts","sourceRoot":"","sources":["../../../server/providers/line-buffer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,OAAO,CAAgB;IAE/B,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE;CAchC"}
@@ -1,9 +1,25 @@
1
+ /**
2
+ * Splits a byte stream into lines. Only each new chunk is searched for a line
3
+ * break, and the pieces of a partial line are joined once, when its break
4
+ * arrives. Re-splitting the whole pending text on every chunk made a long line
5
+ * quadratic: a multi-megabyte line from a provider CLI kept the event loop busy
6
+ * for minutes.
7
+ */
1
8
  export class LineBuffer {
2
- text = '';
9
+ pending = [];
3
10
  accept(chunk) {
4
- this.text += chunk;
5
- const lines = this.text.split(/\r?\n/);
6
- this.text = lines.pop() ?? '';
11
+ const lastBreak = chunk.lastIndexOf('\n');
12
+ if (lastBreak === -1) {
13
+ if (chunk)
14
+ this.pending.push(chunk);
15
+ return [];
16
+ }
17
+ // Keep the break in the joined text so a CR at the end of the previous
18
+ // chunk still pairs with it.
19
+ const complete = this.pending.join('') + chunk.slice(0, lastBreak + 1);
20
+ this.pending = lastBreak + 1 < chunk.length ? [chunk.slice(lastBreak + 1)] : [];
21
+ const lines = complete.split(/\r?\n/);
22
+ lines.pop();
7
23
  return lines;
8
24
  }
9
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meetquinn/animactl",
3
- "version": "0.1.35-canary.797.1.4b8d660",
3
+ "version": "0.1.35",
4
4
  "license": "Apache-2.0",
5
5
  "private": false,
6
6
  "description": "Operator CLI for installing and running Anima.",