1 | import { PassThrough } from 'stream';
|
2 | import { writeTo } from './utils';
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | function ISTEXParseDotCorpus(data, feed) {
|
11 | if (this.isLast()) {
|
12 | return feed.close();
|
13 | }
|
14 | const metadata = this.ezs.metaString(data);
|
15 | const statement = this.ezs.fromString(data);
|
16 | const input = new PassThrough({ objectMode: true });
|
17 | const output = input
|
18 | .pipe(statement)
|
19 | .on('data', (chunk) => {
|
20 | feed.write({ ...metadata, ...chunk });
|
21 | })
|
22 | .on('error', (e) => {
|
23 | feed.write(e);
|
24 | });
|
25 | const handle = new Promise(
|
26 | (resolve, reject) => output.on('error', reject).on('end', resolve),
|
27 | );
|
28 | writeTo(input, metadata, () => {
|
29 | input.end(() => {
|
30 | handle.then(() => {
|
31 | feed.end();
|
32 | });
|
33 | });
|
34 | });
|
35 | }
|
36 |
|
37 |
|
38 | export default {
|
39 | ISTEXParseDotCorpus,
|
40 | };
|