Javascript/HTML5 尝试创建 BinaryStreamReader
我正在尝试用 javascript 创建一个简单的 binaryStreamReader 。目前我有以下内容:
function BinaryStreamReader(file){
var reader = new FileReader();
this.readBytes = function(start, bytes){
reader.readAsBinaryString(file.slice(start,bytes));
reader.onload = function(e){
return e.target.result; //<-- this doesn't work now :P
}
reader.onerror = function(e){
alert("FileError: " + e.target.error.code);
}
}
}
但是,我想像这样使用它
var bsr = new BinaryStreamReader();
var data = bsr.readBytes(0,128);
显然, readBytes() 不会在我的类中返回任何内容。是否可以让它返回 onLoad 返回的任何内容?
I'm trying to create a simple binaryStreamReader in javascript. Currently I have the following:
function BinaryStreamReader(file){
var reader = new FileReader();
this.readBytes = function(start, bytes){
reader.readAsBinaryString(file.slice(start,bytes));
reader.onload = function(e){
return e.target.result; //<-- this doesn't work now :P
}
reader.onerror = function(e){
alert("FileError: " + e.target.error.code);
}
}
}
However, I want to use it like this
var bsr = new BinaryStreamReader();
var data = bsr.readBytes(0,128);
Obviously, readBytes() isn't returning anything in my class. Is it possible to let it return whatever onLoad returns?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这应该可以解决问题...
this should do the trick...