Created
March 21, 2021 23:30
-
-
Save cherihung/b89a94cd8a82e5da7be5bbdca460b9d6 to your computer and use it in GitHub Desktop.
generate any large 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
const fs = require('fs'); | |
const path = require('path'); | |
const bytes_100 = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed mauris augue, vulputate sit amet dolor.\n'; | |
const bytes_400 = bytes_100.repeat(4) | |
const fileName = 'file.txt'; | |
const file = fs.createWriteStream(path.join(__dirname, fileName)); | |
for (let i = 0; i <= 1e6; i++) { | |
file.write(bytes_400); | |
} | |
file.end(); | |
file.once('finish', () => { | |
console.log(`file written: ${fileName}`) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment