Last active
January 5, 2020 15:58
-
-
Save probablycorey/97c07744f525755ebf11 to your computer and use it in GitHub Desktop.
Create large files
This file contains 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
#!/usr/bin/env coffee --nodejs --harmony | |
fs = require 'fs' | |
MB = 1048576 | |
[ignore, ignore, filePath, megabytes] = process.argv | |
fileSize = 0 | |
words = fs.readFileSync('/usr/share/dict/words').toString().split("\n") | |
ws = fs.createWriteStream(filePath) | |
megabytes ?= 0.25 | |
if not filePath? | |
console.log "usage: generate-text output-file [SIZE-IN-MB]" | |
return | |
write = -> | |
while fileSize < MB * megabytes | |
line = "" | |
while line.length < 80 | |
wordIndex = Math.floor(Math.random() * words.length) | |
line += " " + words[wordIndex] | |
fileSize += (line.length + 1) | |
if not ws.write(line + "\n") | |
ws.once('drain', write) | |
return | |
ws.end() | |
write() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Como se usa?