Stream created with ZipWriter
is not read by Response
#407
-
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: 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,
});
}); You can also see it in action on Deno Deploy Playground: https://dash.deno.com/playground/zipjs The |
Beta Was this translation helpful? Give feedback.
Answered by
gildas-lormeau
Mar 22, 2023
Replies: 1 comment 4 replies
-
This is due to the usage of |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
sntran
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
This is due to the usage of
await
. Here's an example showing how to make it work: https://dash.deno.com/playground/bitter-kingfisher-23