1 |
|
2 |
|
3 |
|
4 |
|
5 | const fs = require('fs')
|
6 | const path = require('path')
|
7 | const pickup = require('../')
|
8 | const stream = require('readable-stream')
|
9 |
|
10 | const here = path.dirname(module.filename)
|
11 | const dir = path.join(here, '..', 'test', 'data')
|
12 | const all = fs.readdirSync(dir)
|
13 | const xml = all.filter((p) => { return path.extname(p) === '.xml' })
|
14 | const paths = xml.map((p) => { return path.join(dir, p) })
|
15 |
|
16 | function rnd (paths) {
|
17 | return paths[Math.floor(Math.random() * paths.length)]
|
18 | }
|
19 | function parse (p) {
|
20 | const reader = fs.createReadStream(p)
|
21 | const writer = new stream.PassThrough()
|
22 | reader.pipe(pickup()).pipe(writer)
|
23 | }
|
24 |
|
25 | setInterval(() => { parse(rnd(paths)) }, 10)
|