/ Cases / Creative agency / System
Password-protected galleries with expiration dates, on-the-fly ZIP downloads, automatic thumbnails and a team with change history.
0
copies for the ZIP
1
own domain
/ The problem
Delivering heavy photos and videos to clients depended on third-party services with limits and someone else's branding.
/ What we built
/ How it works
/ Real code
if (match[2] === "zip") {
// …
const { readable, writable } = new TransformStream();
const writer = writable.getWriter();
context.waitUntil(
pumpZip(bucket, items.map((item) => ({ key: item.key, name: item.name, size: item.size })), writer, share.createdAt || Date.now())
.catch((error) => writer.abort(error).catch(() => {})),
);
return new Response(readable, {
headers: {
"content-type": "application/zip",
// …
},
});
}
// …
async function pumpZip(bucket, entries, writer, stampMs) {
// …
const object = await bucket.get(entry.key);
if (object) {
const reader = object.body.getReader();
while (true) {
const { done, value } = await reader.read();
if (done) break;
crc = crcUpdate(crc, value);
written += value.length;
await write(value);
}
■ The ZIP is streamed from R2 while it downloads: no copy is stored and it handles multi-GB folders.
/ Stack