HTML 5文件阅读器同步

时间:2013-07-02 17:20:16

标签: html5 web-worker html5-filesystem

我正在使用web worker和文件系统api来读取文件的内容。但是,每当我尝试读取该文件时,我都会在var message = read.readAsText(fileEntry)的代码行上获得DOM EXCEPTION 8:NOT FOUND ERROR;任何人都可以帮忙解释为什么会这样吗?

path = e.data + "/" + "index.html";

var buffers = [];

var message = "";

var fileEntry = fs.root.getFile(path, {create: false});

var reader = new FileReaderSync();
message = reader.readAsText(fileEntry);

self.postMessage(message);

1 个答案:

答案 0 :(得分:1)

readAsText需要File对象,而不是FileEntrySync对象。调用fileEntry.file()来获取File对象。

path = e.data + "/" + "index.html";
var buffers = [];
var message = "";
var fileEntry = fs.root.getFile(path, {create: false});
var reader = new FileReaderSync();

message = reader.readAsText(fileEntry.file());

self.postMessage(message);