I have a script that parses file data. It starts by using a FileReader to get an array buffer, which it then views through various DataViews and Uint8Arrays, and then does a whole bunch of other stuff with the data. I obviously need to wait for the FileReader to fire onload before I can move forward with the rest of the code, and I don't really like having to put a massive chunk of code inside a reader.onload = function() {} block. Is there a way to make a FileReader behave procedurally and just simply hold up the script while it loads?

有帮助吗?

解决方案

I ended up moving this script to a web worker, and discovered FileReaderSync, which is EXACTLY what I was after. FileReaderSync only works with web workers however, but if you are looking for this type of solution your script should probably be running in a web worker anyway.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top