import { serve } from "https://deno.land/std@0.177.0/http/server.ts";
import {
ZipWriter,
} from "https://deno.land/x/zipjs@v2.6.79/index.js";
serve(async (req: Request) => {
// Creates a TransformStream object, the zip content will be written in the
// `writable` property. The `readable` property is responded to client.
const { readable, writable } = new TransformStream();
const zipWriter = new ZipWriter(writable);
const entry = await zipWriter.add("hello.txt", new Blob(["Hello world!"]).stream());
console.log(entry);
await zipWriter.close();
const headers = new Headers();
headers.set("Content-Disposition", `attachment; filename="hello.zip"`);
return new Response(readable, {
// headers,
});
});
Using the Hello World with Streams example, I try to write a server that responds with zip file, but it does not work.
The minimal code for such server is below:
You can also see it in action on Deno Deploy Playground: https://dash.deno.com/playground/zipjs
The
console.log(entry)
is never called. The whole process just hangs.