Created
January 15, 2024 16:07
-
-
Save fullstackzach/60b1b6fea7c22a96e51dddf4dac207cd to your computer and use it in GitHub Desktop.
Create an arbitrary file of any size, useful for testing
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
// 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