
3 Ways to ZIP Files Stored on Cloudflare R2
You have files sitting in Cloudflare R2 and a user just clicked "Download All." Now what? R2 doesn't have a built-in "zip these objects" operation. You need to figure it out yourself. After building a file processing API that has archived 550K+ files and 10TB+ on R2, here are the three approaches I've found — each with very different trade-offs. Approach 1: Download Locally, ZIP, Re-upload The most obvious approach. Pull files down, zip them on your server, upload the archive back to R2 (or serve it directly). // Pseudocode const files = await Promise . all ( keys . map ( key => r2 . get ( key )) ); const zip = new JSZip (); files . forEach ( f => zip . file ( f . name , f . body )); const archive = await zip . generateAsync ({ type : ' nodebuffer ' }); // Serve or upload archive Pros: Simple to implement Works with any ZIP library (JSZip, archiver, etc.) Full control over the ZIP structure Cons: Memory killer. You're buffering everything. 100 files × 50MB = 5GB in RAM Slow. Download a
Continue reading on Dev.to Webdev
Opens in a new tab

