문제

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