Open sethdorris opened 8 years ago
I used forEach(), I'd like to know a better way.
configZip.loadAsync(rawConfigZipBuffer)
.then(function(configZip) {
//
// generate a table of contents
//
configZip.forEach(function(filePath, file) {
...
A bit late: promises are chainable, if you return a promise in a then
, its result will be available in the next then
. See the upgrade guide for an other example (look for Promises are chainable
).
JSZip.loadAsync(binaryContent).then(function (zip) {
return zip.file("path/to/file.txt").async("text");
}).then(function (txt) {
console.log("the content is", txt);
});
@sethdorris does this solve your issue ?
If you want to read all the contents in a zip, and return it all at once as an object array with the file name.. You can do:
export async function getZipFilesContent (data) {
const zipContent = []
const promises = []
const zip = (await JSZip.loadAsync(data))
zip.forEach(async (relativePath, file) => {
const promise = file.async('string')
promises.push(promise)
zipContent.push({
file: relativePath,
content: await promise
})
})
await Promise.all(promises)
return zipContent
}
If you want to read all the contents in a zip, and return it all at once as an object array with the file name.. You can do:
export async function getZipFilesContent (data) { const zipContent = [] const promises = [] const zip = (await JSZip.loadAsync(data)) zip.forEach(async (relativePath, file) => { const promise = file.async('string') promises.push(promise) zipContent.push({ file: relativePath, content: await promise }) }) await Promise.all(promises) return zipContent }
can you give your demo project?
Hey did anyone have an issue with 2 same zip files where one has inside the zipContents.files a structure and the other one which holds the same content differently?
I cannot find documentation on this .. is there a good example on how to do this?