admin管理员组文章数量:1302341
I will have a web worker to parse huge text file (200000 lines, simple syntax though). I expect user to submit that file wia drag'n'drop or otherwise, obtaining a File
object:
var work = new Worker("parser.js")
document.addEventListener("drop", function(e) {
e.preventDefault();
var dt = e.dataTransfer;
var files = dt.files;
if(files.length>0) {
var firstFile = files[0]
var reader = new FileReader();
//SEND FILE TO WORKER?
}
});
I heard of Transferable objects. Is there a way to transfer file to Worker? In a way that GUI thread will not be slowed by reading the file?
I will have a web worker to parse huge text file (200000 lines, simple syntax though). I expect user to submit that file wia drag'n'drop or otherwise, obtaining a File
object:
var work = new Worker("parser.js")
document.addEventListener("drop", function(e) {
e.preventDefault();
var dt = e.dataTransfer;
var files = dt.files;
if(files.length>0) {
var firstFile = files[0]
var reader = new FileReader();
//SEND FILE TO WORKER?
}
});
I heard of Transferable objects. Is there a way to transfer file to Worker? In a way that GUI thread will not be slowed by reading the file?
Share asked Oct 23, 2015 at 15:22 Tomáš ZatoTomáš Zato 53.3k63 gold badges310 silver badges825 bronze badges 1- There is a great tutorial on this here: html5rocks./en/tutorials/file/filesystem-sync , you can even handle the fileReader on the worker – juvian Commented Oct 23, 2015 at 15:35
1 Answer
Reset to default 10Some browsers (can't find a patibility table) support passing File
objects through the web worker postMessage
because they now use the structured clone algorithm to handle the message parameters. This would probably be the most efficient method for those browsers which support it.
Further research seems to indicate that structured cloning is supposed to be available on: Chrome 13+, Firefox 8+, IE10+, Opera 11.5+, Safari 5.1+
版权声明:本文标题:javascript - Pass submited file to web worker by refference with as little overhead as possible - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741712118a2393904.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论