MCPcopy Index your code
hub / github.com/nodejs/node / main

Function main

benchmark/fs/read-stream-throughput.js:19–67  ·  view source on GitHub ↗
(conf)

Source from the content-addressed store, hash-verified

17});
18
19function main(conf) {
20 const { encodingType, highWaterMark, filesize } = conf;
21 let { n } = conf;
22
23 let encoding = '';
24 switch (encodingType) {
25 case 'buf':
26 encoding = null;
27 break;
28 case 'asc':
29 encoding = 'ascii';
30 break;
31 case 'utf':
32 encoding = 'utf8';
33 break;
34 default:
35 throw new Error(`invalid encodingType: ${encodingType}`);
36 }
37
38 // Make file
39 const buf = Buffer.allocUnsafe(filesize);
40 if (encoding === 'utf8') {
41 // ü
42 for (let i = 0; i < buf.length; i++) {
43 buf[i] = i % 2 === 0 ? 0xC3 : 0xBC;
44 }
45 } else if (encoding === 'ascii') {
46 buf.fill('a');
47 } else {
48 buf.fill('x');
49 }
50
51 try {
52 fs.unlinkSync(filename);
53 } catch {
54 // Continue regardless of error.
55 }
56 const ws = fs.createWriteStream(filename);
57 ws.on('close', runTest.bind(null, filesize, highWaterMark, encoding, n));
58 ws.on('drain', write);
59 write();
60 function write() {
61 do {
62 n--;
63 } while (false !== ws.write(buf) && n > 0);
64 if (n === 0)
65 ws.end();
66 }
67}
68
69function runTest(filesize, highWaterMark, encoding, n) {
70 assert.strictEqual(fs.statSync(filename).size, filesize * n);

Callers

nothing calls this directly

Calls 6

fillMethod · 0.80
writeFunction · 0.70
createWriteStreamMethod · 0.65
unlinkSyncMethod · 0.45
onMethod · 0.45
bindMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…