Skip to content

Instantly share code, notes, and snippets.

@cherihung
Created March 21, 2021 23:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cherihung/b89a94cd8a82e5da7be5bbdca460b9d6 to your computer and use it in GitHub Desktop.
Save cherihung/b89a94cd8a82e5da7be5bbdca460b9d6 to your computer and use it in GitHub Desktop.
generate any large file
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