Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/puliczek/cloudflare-to-zip

Microservice to zip files on Cloudflare Worker
https://github.com/puliczek/cloudflare-to-zip

api cloudflare cloudflare-api cloudflare-worker cloudflare-workers zip zipper

Last synced: about 1 month ago
JSON representation

Microservice to zip files on Cloudflare Worker

Awesome Lists containing this project

README

        



🤝 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](https://hono.dev/) framework
- 🗜️ Uses [littlezipper](https://www.npmjs.com/package/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:
```bash
git clone https://github.com/Puliczek/cloudflare-to-zip.git
cd cloudflare-to-zip
```

2. Install dependencies:
```bash
npm install
```

## Development

To run the project locally:

```bash
npm run dev
```

This will start the development server using Wrangler.

## Deployment

Deploy to Cloudflare Workers:

```bash
npm run deploy
```

## API Documentation

### POST /zip

Creates a ZIP archive from the provided files.

#### Request Body

```json
[
{
"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

```typescript
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

- [Cloudflare Workers](https://workers.cloudflare.com/)
- [Hono](https://hono.dev/) - Fast, Lightweight, Web-standards Web Framework
- [TypeScript](https://www.typescriptlang.org/)
- [littlezipper](https://www.npmjs.com/package/littlezipper)

## License

MIT License

## Contributing

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