-
Can you write a code snippet that zips a folder (My Directory) containing multiple mp4 files and then downloads the zipped file as my-directory.zip? I tried this but didn't get the best results
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Look, this is not StackOverflow, but I guess what you're trying to implement is something like this: import { File } from 'https://cdn.skypack.dev/megajs'
import JSZip from 'https://cdn.skypack.dev/jszip'
import saveAs from 'https://cdn.skypack.dev/file-saver'
const folder = File.fromURL('link to some folder') // you can also load it from your account
await folder.loadAttributes() // this is not needed if you load from your account
const handleFolder = async (megaFolder, zipFolder) => {
if (!megaFolder.children) return
for (const file of megaFolder.children) {
if (file.directory) {
await handleFolder(file, zip.folder(file.name))
} else {
zip.file(file.name, await file.downloadBuffer())
}
}
}
const zip = new JSZip()
await handleFolder(folder, zip)
saveAs(await zip.generateAsync({type: 'blob'}), 'folder.zip') I didn't tested this code, but should from my experience using those three libraries it might work. Maybe. I don't know. Well most of this question is not related to the library but JavaScript related so that's better suited to StackOverflow. Here are the keypoints of the above example (some related to the library):
|
Beta Was this translation helpful? Give feedback.
Look, this is not StackOverflow, but I guess what you're trying to implement is something like this: