Hi,
I use this code to download a zip from the web and read that, but I do not know what I have to do after that:
$http.post(url, data, {responseType: 'arraybuffer'})
.then(function successCallback(file_response) {
var file = new Blob([file_response.data], {type: 'application/zip'});
var zip = new JSZip();
zip.loadAsync(file)
.then(function (content) {
// use content
});
}, function errorCallback(file_error) {
});
What can I do with "content"? I need to open it and read the content of the files (actually I have always one file). How can I do that?
Thanks.
content is actually the up-to-date zip object: you use file(name) to get the entry then async to get the full content for example.
zip.loadAsync(file).then(function (content) {
zip.file("my_file.png").async("uint8array").then(...);
})
If you only have one file, you can also chain promises directly:
JSZip.loadAsync(file_response.data).then(function (zip) {
return zip.file("my_file.png").async("uint8array");
}).then(function (pngContent) {
// use the uint8array here
})
Most helpful comment
contentis actually the up-to-datezipobject: you use file(name) to get the entry then async to get the full content for example.If you only have one file, you can also chain promises directly: