forked from harvard-lil/scoop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebugKit.js
More file actions
34 lines (29 loc) · 927 Bytes
/
debugKit.js
File metadata and controls
34 lines (29 loc) · 927 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
import fs from 'fs';
export async function writeAllExchangesToFile(exchanges, path) {
// Create a writable stream to the file
const stream = fs.createWriteStream(path, { flags: 'w' });
stream.write(`"url"; "response"; "startLine"; "bodyLength"\n`);
for (const ex of exchanges) {
// console.log(ex.url)
stream.write(`"` + ex.url + `"`);
if (!ex.response)
stream.write(`; "NO"`)
else {
const response = ex.response
stream.write(`; "YES"`)
stream.write(`; "` + response.startLine + `"`)
let bodyLen = 0;
try {
let body = response.body
bodyLen = body.length
}
catch (e) {
bodyLen = -1
}
stream.write(`; "` + bodyLen + `"`)
}
stream.write('\n');
}
// Close the stream
stream.end();
}