Skip to content

Puliczek/cloudflare-to-zip

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🤝 Show your support - give a ⭐️ if you liked the content

X (formerly Twitter) Follow


cloudflare-to-zip

Microservice to zip files on Cloudflare Worker - A serverless solution for creating ZIP archives from base64-encoded files directly on the edge.

About

This lightweight microservice leverages Cloudflare Workers to create ZIP archives on the fly. Perfect for scenarios where you need to bundle multiple files into a ZIP archive without server infrastructure. The service accepts base64-encoded files via a simple REST API endpoint and returns a ready-to-download ZIP file.

Features

  • 📦 Create ZIP archives from multiple files
  • 🚀 Fast and efficient processing using Cloudflare Workers
  • 💾 Handles base64-encoded file data
  • 📅 Automatically generates timestamped ZIP filenames
  • 🔒 Built with TypeScript for type safety
  • ⚡ Powered by Hono framework
  • 🗜️ Uses littlezipper for ZIP creation

Limitations

⚠️ Current testing has been performed with:

  • Maximum of 10 images simultaneously
  • Each file up to 200KB in size
  • Larger files or higher volumes need additional testing

Installation

  1. Clone the repository:
git clone https://github.com/Puliczek/cloudflare-to-zip.git
cd cloudflare-to-zip
  1. Install dependencies:
npm install

Development

To run the project locally:

npm run dev

This will start the development server using Wrangler.

Deployment

Deploy to Cloudflare Workers:

npm run deploy

API Documentation

POST /zip

Creates a ZIP archive from the provided files.

Request Body

[
    {
        "name": "test1.txt",
        "base64": "data:text/plain;base64,SGVsbG8gV29ybGQh"
    },
    {
        "name": "test2.txt",
        "base64": "data:text/plain;base64,VGhpcyBpcyBhIHRlc3QgZmlsZQ=="
    }
]

Response

  • Success: Returns a ZIP file with application/zip content type
  • Error: Returns JSON with error details
    • 400: No files provided
    • 500: Processing error

Example Usage

const response = await fetch('https://your-worker.workers.dev/zip', {
  method: 'POST',
  body: JSON.stringify([
    {
      name: 'example.txt',
      base64: 'data:text/plain;base64,SGVsbG8gV29ybGQh'
    }
  ])
});

if (response.ok) {
  const blob = await response.blob();
  // Handle the ZIP file
}

Technologies

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.