Can we zip folders? #233
Answered
by
gildas-lormeau
gildas-lormeau
asked this question in
Q&A
-
Does zip.js support deflating folders? In Chrome, you can drag folders onto a window/DOM element, and access the contents of that folder. It would be great to be able to deflate a dragged folder. (see #226) |
Beta Was this translation helpful? Give feedback.
Answered by
gildas-lormeau
Mar 12, 2021
Replies: 1 comment
-
Here's an example of how to achieve this with zip.js <input type=file multiple webkitdirectory id="files">
<script src="https://cdn.jsdelivr.net/npm/@zip.js/zip.js@2.2.22/dist/zip.min.js"></script>
<script>
files.onchange = async event => {
document.body.innerHTML = "";
const zipWriter = new zip.ZipWriter(new zip.Data64URIWriter("application/zip"));
await Promise.all(Array.from(event.target.files).map(async file => {
await zipWriter.add(file.webkitRelativePath, new zip.BlobReader(file));
document.body.innerHTML += " - " + file.webkitRelativePath + "<br>";
}));
document.body.innerHTML += "<br>";
const link = document.createElement("a");
link.href = await zipWriter.close();
link.download = "test.zip";
link.textContent = "Download";
document.body.appendChild(link);
}
</script> |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
gildas-lormeau
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's an example of how to achieve this with zip.js