(conf)
| 17 | }); |
| 18 | |
| 19 | function 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 | |
| 69 | function runTest(filesize, highWaterMark, encoding, n) { |
| 70 | assert.strictEqual(fs.statSync(filename).size, filesize * n); |
nothing calls this directly
no test coverage detected
searching dependent graphs…