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/[email protected]/http/server.ts";
import {
ZipWriter,
} from "https://deno.land/x/[email protected]/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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in 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