🪟 Windows TippsThe Gemini desktop app is now available for Windows(11.09.2026 um 17:06 Uhr)
🪟 Windows TippsHeader and Footer not showing in Excel(14.09.2026 um 22:43 Uhr)
🕵️ SicherheitslückenBurn Out, Or Fade Away(14.09.2026 um 14:25 Uhr)
🪟 Windows TippsKB5129194 Windows 11 26H1 Out of Band Update - Deskmodder.de(14.09.2026 um 19:25 Uhr)
🪟 Windows TippsThe Gemini desktop app is now available for Windows(11.09.2026 um 17:06 Uhr)
🪟 Windows TippsHeader and Footer not showing in Excel(14.09.2026 um 22:43 Uhr)
🕵️ SicherheitslückenBurn Out, Or Fade Away(14.09.2026 um 14:25 Uhr)
🪟 Windows TippsKB5129194 Windows 11 26H1 Out of Band Update - Deskmodder.de(14.09.2026 um 19:25 Uhr)

🔧 Programmierung 🕛 vor 1 Monat 2 Min Lesezeit
0

How to generate a valid file of any exact size, in the browser

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

I needed a 10 MB PDF to test an upload limit. Not "about 10 MB" — exactly 10,485,760 bytes. Every generator I found gave me fixed sizes or made me wait for a server download.



So I looked into doing it in the browser. The interesting part wasn't the size. It was keeping the file valid while hitting an arbitrary byte count.






The naive approach breaks the file



The obvious move is: make a real file, then append junk bytes until you hit the target.




CODE
const blob = new Blob([realPdf, padding]); // ← corrupt






For most formats this produces a broken file. A PDF reader follows the cross-reference table to a byte offset; trailing garbage after %%EOF can throw it off. A PNG decoder walks length-prefixed chunks; extra bytes at the end aren't a valid chunk.



The trick is that every format already reserves a legal place for extra data. You just have to put the padding there.






Padding where the spec allows it





  • PNG → a tEXt metadata chunk. It has a length prefix and a CRC-32, so decoders read exactly its declared length and skip the rest. Perfectly valid.


  • PDF → an unreferenced content stream. Same mechanism PDF writers use for incremental updates — the xref table just doesn't point at it.


  • ZIP / DOCX / XLSX → a stored (uncompressed) entry inside the archive.


  • JPEGCOM comment segments, up to 65,533 bytes each.



For PNG, the padded chunk needs a correct CRC or the decoder rejects it:




CODE
function pngChunk(type, data) {
const body = concat(type, data);
const crc = crc32(body); // must be correct
return concat(uint32(data.length), body, uint32(crc));
}






Get the CRC right and the file opens everywhere — the padding is invisible.






Why the browser part matters



Because nothing crosses the network, size barely affects speed. Assembling a 100 MB file is a memory operation, not a download — it lands in tens of milliseconds. And the file never leaves your machine, so there's no upload, no storage, nothing to log.



I verified the output against real parsers — pypdf reads the PDF text, Pillow decodes the PNG, openpyxl opens the XLSX. They're genuinely valid files, just padded.



I turned this into a free tool (ByteRivet) that does 19 formats at any exact size, all in-browser. But the padding-without-corruption idea is the reusable part — worth knowing whenever you need a fixture at a precise size.



What's the weirdest exact-size requirement you've hit in testing?

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
The Gemini desktop app is now available for Windows
1 Quelle
Header and Footer not showing in Excel
1 Quelle
Burn Out, Or Fade Away