| 81 | |
| 82 | let totalWritten = 0; |
| 83 | function writeData() { |
| 84 | if (totalWritten >= 10000) { |
| 85 | stream.end(); |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | const chunk = str.slice(totalWritten, totalWritten + 1000); |
| 90 | if (stream.write(chunk)) { |
| 91 | totalWritten += chunk.length; |
| 92 | setImmediate(common.mustCall(writeData)); |
| 93 | } else { |
| 94 | stream.once('drain', common.mustCall(() => { |
| 95 | totalWritten += chunk.length; |
| 96 | setImmediate(common.mustCall(writeData)); |
| 97 | })); |
| 98 | } |
| 99 | }; |
| 100 | |
| 101 | stream.on('finish', common.mustCall(() => { |
| 102 | fs.readFile(dest, 'utf8', common.mustSucceed((data) => { |