Replies: 1 comment
-
The example you provided is not clear enough to understand what you want to achieve precisely. For example, a "dict" does not exist in JS. I guess you're referring to an object even if the structure looks like an array? I guess "dir1/" is a folder and I guess "asdffdafdsfs" is a simple file (not a folder, not a zip)? I also guess "dir1/dir1-1" and "dir1/dir1-2" are folders even there isn't any ending "/"? That's a lot of ambiguity for a simple question... I guess you want something similar to this: https://jsfiddle.net/8196k3j4 import * as zip from "https://unpkg.com/@zip.js/[email protected]/index.js";
main();
async function main() {
const urls = {
1: "https://unpkg.com/@zip.js/[email protected]/tests/all/test-blob.js",
2: "https://unpkg.com/@zip.js/[email protected]/tests/all/test-base64.js",
3: "https://unpkg.com/@zip.js/[email protected]/tests/all/test-array.js"
};
const filenames = {
1: "dir1/",
2: "dir1/dir1-1/",
3: "dir1/dir1-2/"
};
// Creates the zip file
const zipWriter = new zip.ZipWriter(new zip.BlobWriter("application/zip"));
await Promise.all(Object.keys(urls).map(async key => {
const url = urls[key];
const filename = filenames[key] + url.split("/").pop();
await zipWriter.add(filename, new zip.HttpReader(url));
}));
// Downloads the Blob object containing the zip file.
const anchorElement = document.createElement("a");
anchorElement.href = URL.createObjectURL(await zipWriter.close());
anchorElement.download = "test.zip";
anchorElement.click();
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
It's hard for me to learn how to use zip.js, wuwu~.
Could you give me an example to solve this problom?
eg:
you have a file dict:
another dict:(stand for the per file's path)
Finally, you should download all files to a zip .
Beta Was this translation helpful? Give feedback.
All reactions