Skip to content

Instantly share code, notes, and snippets.

@fullstackzach
Created January 15, 2024 16:07
Show Gist options
  • Save fullstackzach/60b1b6fea7c22a96e51dddf4dac207cd to your computer and use it in GitHub Desktop.
Save fullstackzach/60b1b6fea7c22a96e51dddf4dac207cd to your computer and use it in GitHub Desktop.
Create an arbitrary file of any size, useful for testing
// this can be thrown into chrome dev tools to create a dummy file for testing
function createLargeFile(fileName, fileSizeInGB) {
const chunkSize = 1024 * 1024 * 10; // 10MB chunk size
let fileSize = fileSizeInGB * 1024 * 1024 * 1024; // Convert GB to bytes
let parts = [];
while (fileSize > 0) {
let size = Math.min(chunkSize, fileSize);
let part = new Uint8Array(size);
parts.push(part);
fileSize -= size;
}
let blob = new Blob(parts, { type: 'application/octet-stream' });
let link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = fileName;
link.click();
}
createLargeFile('2GB_dummy_file', 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment