1 | import JSONStream from 'JSONStream';
|
2 | import { writeTo } from './utils';
|
3 |
|
4 | function JSONParse(data, feed) {
|
5 | if (!this.handle) {
|
6 | const separator = this.getParam('separator', '*');
|
7 | this.handle = JSONStream.parse(separator);
|
8 | this.handle.on('data', obj => feed.write(obj));
|
9 | }
|
10 | if (!this.isLast()) {
|
11 | writeTo(this.handle,
|
12 | data,
|
13 | () => feed.end());
|
14 | } else {
|
15 | this.handle.end();
|
16 | process.nextTick(() => {
|
17 | feed.close();
|
18 | });
|
19 | }
|
20 | }
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | export default {
|
31 | JSONParse,
|
32 | };
|