-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
41 lines (31 loc) · 845 Bytes
/
index.js
File metadata and controls
41 lines (31 loc) · 845 Bytes
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
const fs = require('fs');
const path = require('path');
const { converter } = require('./converter');
async function main() {
let args = process.argv.slice(2);
if (args.length === 0) {
console.log('please specify in the args the path of log file');
return;
}
if (args.length > 1) {
console.log('there are too much args');
return;
}
if (!fs.existsSync(args[0])) {
console.log('the log file doesn\'t exist');
return;
}
const txt = fs.readFileSync(args[0], 'utf-8');
const ms = converter(txt);
if(ms === null) {
console.log('error');
return;
}
await saveToDisk(ms, path.join(process.cwd(), path.basename(args[0], path.extname(args[0])) + '.pcap'));
}
async function saveToDisk(ms, filePath) {
const ws = fs.createWriteStream(filePath);
ws.write(ms.read());
ws.end();
}
main();