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