Open shakthifuture opened 4 years ago
I did this:
async compressXmlFile(file: File): Promise<File> {
let count = 0;
var zip = new JSZip();
let newFile: File;
zip.file(file.name, file);
await zip.generateAsync({ type: 'blob' }).then((blob: Blob) => {
newFile = new File([blob], file.name.split('.')[0] + '.zip', {
lastModified: file.lastModified,
type: 'application/zip'
});
});
return newFile;
}
zip.generateAsync({ type: 'file' })
and ZipObject#loadAsync('file')
would both be very helpful.
That snippet above shows that it ought to be fairly trivial.
FWIW I used the following for reading zipped files as File
objects.
const zip = await JSZip.loadAsync(file);
for (let zobj of Object.values(zip.files)) {
if (zobj.dir) continue;
const zblob = await zobj.async("blob");
const zfile = new File([zblob], path.basename(zobj.name), {
lastModified: zobj.date.getTime(),
type: 'application/zip'
});
processFile(zfile, fp + "/" + zobj.name);
}
await zobj.async("blob"); the blob object doesn't included type. application/zip is not the file type.
There is a separate issue mentioning mime types if you're having trouble: https://github.com/Stuk/jszip/issues/626
Hi,
Please let me know how to convert "JSZipObject" to a standard "File" object?
Thank you.