Created
November 28, 2011 13:27
-
-
Save timoxley/1400393 to your computer and use it in GitHub Desktop.
slowly write random data to file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var dataTotal = 5242880 // 5 meg | |
| var filePath = path.join(process.cwd, 'test', 'testData') | |
| var randomData = function() { | |
| return String(Math.round(Math.random())) | |
| } | |
| var stream = fs.createWriteStream(filePath) | |
| stream.on('close', function() { | |
| done() | |
| }) | |
| var dataSize = 0 | |
| stream.on('open', function() { | |
| while(dataSize < dataTotal) { | |
| dataSize++ | |
| var data = randomData() | |
| stream.write(data, 'binary') | |
| if (dataSize >= dataTotal) { | |
| stream.end() | |
| stream.destroySoon() | |
| } | |
| } | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment