Skip to content

Instantly share code, notes, and snippets.

@probablycorey
Last active January 5, 2020 15:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save probablycorey/97c07744f525755ebf11 to your computer and use it in GitHub Desktop.
Save probablycorey/97c07744f525755ebf11 to your computer and use it in GitHub Desktop.
Create large files
#!/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()
@laramjo
Copy link

laramjo commented Feb 18, 2015

Como se usa?

@rictorres
Copy link

generate-text five-megabytes-of-words.txt 5

Source: atom/atom#307 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment