Skip to content

Instantly share code, notes, and snippets.

@timoxley
Created November 28, 2011 13:27
Show Gist options
  • Select an option

  • Save timoxley/1400393 to your computer and use it in GitHub Desktop.

Select an option

Save timoxley/1400393 to your computer and use it in GitHub Desktop.
slowly write random data to file
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