-
Notifications
You must be signed in to change notification settings - Fork 156
/
Copy pathstreamjson.js
28 lines (25 loc) · 910 Bytes
/
streamjson.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Stream read a json file and print it as xml to the console
const { parser } = require('stream-json/Parser');
const { streamArray } = require('stream-json/streamers/StreamArray');
//const {streamValues } = require('stream-json/streamers/StreamValues');
const fs = require('fs');
const map = require('through2-map');
const { SitemapStream } = require('sitemap');
// our data stream:
// {total: 123456789, meta: {...}, data: [...]}
// we are interested in 'data'
/*
const pipeline = fs
.createReadStream("./tests/mocks/perf-data.json.txt")
.pipe(parser())
.pipe(streamValues())
.pipe(map.obj(chunk => chunk.value))
.pipe(new SitemapStream());
*/
const pipeline = fs
.createReadStream('../tests/mocks/perf-data.json')
.pipe(parser())
.pipe(streamArray())
.pipe(map.obj((chunk) => chunk.value))
.pipe(new SitemapStream());
pipeline.on('data', (data) => console.log(data));