1 |
|
2 | import { jsonStringifyGenerator } from './json-stringify.js';
|
3 | export class JSONStringifyStream extends TransformStream {
|
4 | constructor() {
|
5 | let first;
|
6 | super({
|
7 | start(controller) {
|
8 | first = true;
|
9 | controller.enqueue('[');
|
10 | },
|
11 | async transform(obj, controller) {
|
12 | if (!first)
|
13 | controller.enqueue(',');
|
14 | else
|
15 | first = false;
|
16 | for await (const chunk of jsonStringifyGenerator(obj)) {
|
17 | controller.enqueue(chunk);
|
18 | }
|
19 | },
|
20 | flush(controller) {
|
21 | controller.enqueue(']');
|
22 | },
|
23 | });
|
24 | }
|
25 | }
|
26 |
|
\ | No newline at end of file |