-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiff.js
47 lines (35 loc) · 1.01 KB
/
diff.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const LineByLineReader = require('line-by-line')
const csvWriter = require('csv-write-stream')
const fs = require('fs')
const allPath = process.argv[2]
const donePath = process.argv[3]
const diffPath = process.argv[4]
const doneLr = new LineByLineReader(donePath)
const writer = csvWriter({sendHeaders: false})
writer.pipe(fs.createWriteStream(diffPath))
const done = []
doneLr.on('line', line => {
const csv = line.split(',')
const rank = csv[0].trim()
const hostname = csv[1]
if (!rank.match(/\d+/)) {
console.warn('invalid line:', line)
return
}
done[rank] = hostname
})
doneLr.on('end', () => {
const allLr = new LineByLineReader(allPath)
allLr.on('line', line => {
const csv = line.split(',')
const rank = csv[0]
const hostname = csv[1]
if (!rank || !hostname) {
console.warn('invalid line:', line)
return
}
if (!done[rank]) {
writer.write({rank, hostname})
}
})
})