How to specify filename with client-zip #3
-
|
I'd like to pass the readable stream to client-zip while providing a filename (different than the fetch response filename). |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Yes. You need to transform the stream of Responses into a stream of objects with a const dlstream = new DownloadStream(yourInputURLsOrRequests)
async function *namedInput() {
for await (const response of dlstream) yield {
name: "your custom name.ext",
input: response,
lastModified: response.headers.get('Last-Modified')
}
}
const zipRersponse = downloadZip(namedInput())Sometime in the near future, it will be possible to use a TransformStream (because all ReadableStreams will be AsyncIterable like a DownloadStream) or the |
Beta Was this translation helpful? Give feedback.
Yes. You need to transform the stream of Responses into a stream of objects with a
nameproperty (your custom filename) and aninputproperty (the Response) and optionallylastModifiedas specified here. You can do that easily with an async generator (because DownloadStreams are AsyncIterable) :Sometime in the near future, it will be possible to use a TransformStream (because all Readable…