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.
Wait for FileReader - Procedural Javascript
-
09-10-2022 - |
문제
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 DataView
s and Uint8Array
s, 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?
해결책
제휴하지 않습니다 StackOverflow