101arrowz / fflate

High performance (de)compression in an 8kB package

Home Page:https://101arrowz.github.io/fflate

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Browser tab freezes when using unzip

linkurzweg opened this issue · comments

I am using fflate in a Vue.js 3 app and it it really a lot faster than other packages :)

However, I have the following problem (not sure if it's a bug or if I'm just using it wrong): I'm using unzip to extract a lot of xml files from a zip archive, parse them and push them into a store. As soon as the unzipping operation is started the UI of my vue app completely freezes, nothing is clickable anymore and my loading animation also stops moving.

My code looks like this:

loading.value = true
const fileBuffer = await file.file.arrayBuffer()
const archive = new Uint8Array(fileBuffer)
const unzippedFiles = []

unzip(archive, (err, unzipped) => {
  if (err) {
    console.log(err)
  }
  for (const file in unzipped) {
    const fileString = strFromU8(unzipped[file])
    unzippedFiles.push(parser.parse(fileString, {}, true))
  }
})

store.setDocuments(unzippedFiles)
loading.value = false

What can I do to prevent the freezing? Thank you!

Could you try just running unzip without the parsing logic afterwards? That function is actually specifically designed NOT to block the UI, so it's a bit weird that it does.

@101arrowz I tried that already. It takes less time processing the zip file, but everything still freezes. Yes, I read that it is supposed to be non-blocking and to run in another thread...

Could you send me the file that causes this so I can debug further?

I'll ask if I'm allowed to :)

@101arrowz Sorry, I'm not allowed to send it because it contains confidential information. I understand if you can't investigate any further in this.

Ok that's fine. I'm going to guess that this will be solved by compressing as many files as possible on another thread rather than having an arbitrary byte cutoff by implementing the worker pool from #58, so I'm closing in favor of that issue. If you want to know when this is resolved follow #58; for now you should probably just make a web worker manually and call unzipSync.