-
-
Notifications
You must be signed in to change notification settings - Fork 686
Expand file tree
/
Copy pathindex.js
More file actions
62 lines (52 loc) · 1.43 KB
/
Copy pathindex.js
File metadata and controls
62 lines (52 loc) · 1.43 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import assert from "node:assert";
import MultipartParser from "../src/parsers/Multipart.js";
const parser = new MultipartParser();
const customBoundary = "-----------------------------168072824752491622650073";
const mb = 1000; // 1GB
const buf = createMultipartBuffer(customBoundary, mb * 1024 * 1024);
const calls = {
partBegin: 0,
headerField: 0,
headerValue: 0,
headerEnd: 0,
headersEnd: 0,
partData: 0,
partEnd: 0,
end: 0,
};
const start = performance.now();
parser.initWithBoundary(customBoundary);
parser.on("data", ({ name }) => {
calls[name] += 1;
});
parser.write(buf);
const duration = performance.now() - start;
const mbPerSec = (mb / (duration / 1000)).toFixed(2);
console.log(`${mbPerSec} mb/sec`);
function createMultipartBuffer(boundary, size) {
const head =
`--${boundary}\r\n` +
`content-disposition: form-data; name="field1"\r\n` +
`\r\n`;
const tail = `\r\n--${boundary}--\r\n`;
const buffer = Buffer.alloc(size);
buffer.write(head, 0, "ascii");
buffer.write(tail, buffer.length - tail.length, "ascii");
return buffer;
}
process.on("exit", () => {
assert.deepStrictEqual(calls, {
partBegin: 1,
headerField: 1,
headerValue: 1,
headerEnd: 1,
headersEnd: 1,
partData: 1,
partEnd: 1,
end: 1,
});
// Object.keys(events).forEach((k) => {
// console.log(k, events[k]);
// // assert.equal(callbacks[k], 0, `${k} count off by ${callbacks[k]}`);
// });
});