Download a Readable stream to Zip file in JavaScript

Viewed 1147

Currently, I make a fetch request, which returns a readable stream (response body is a ReadableStream). I'm trying to save this to a users device as a zip file.

getDownload(id, downloadName).then(download => {
            const blob = new Blob([download]);

            const link = document.createElement("a");
            link.href = URL.createObjectURL(blob);
            link.download = "fileName";
            link.target = "_blank";
            link.setAttribute("type", "hidden");

            document.body.appendChild(link);

            link.click();
            link.remove();
})

This however, downloads into a text file with the contents

[object Response]

I know that the response is not corrupted, as I have been able to stream it in Chrome, however, this functionality is being added, so I can download in Safari.

How can I get the readable stream downloaded as a zip directory?

0 Answers
Related