HTML 5のFileWriter継承拡張、メソッドまたはオブジェクトの追加
2653 ワード
JavaScript , , FileWriter 。
function FileWriter(writer)
{
this.writer = writer;
// EventTarget
this.addEventListener = function(type, listener, useCapture) {
this.writer.addEventListener(type, listener, useCapture);
};
this.removeEventListener = function(type, listener, useCapture) {
this.writer.removeEventListener(type, listener, useCapture);
};
this.dispatchEvent = function(evt) {
this.writer.dispatchEvent(evt);
};
// FileSaver
const INIT = this.writer.INIT;
const WRITING = this.writer.WRITING;
const DONE = this.writer.DONE;
this.__defineGetter__("readyState", function(){return this.writer.readyState;});
this.__defineGetter__("error", function(){return this.writer.error;});
this.__defineGetter__("fileName", function() {return this.writer.fileName;});
this.abort = function() {
this.writer.abort();
};
this.__defineGetter__("onwritestart", function(){return this.writer.onwritestart;});
this.__defineGetter__("onprogress", function(){return this.writer.onprogress;});
this.__defineGetter__("onabort", function(){return this.writer.onabort;});
this.__defineGetter__("onwrite", function(){return this.writer.onwrite;});
this.__defineGetter__("onerror", function(){return this.writer.onerror;});
this.__defineGetter__("onwriteend", function(){return this.writer.onwriteend;});
this.__defineSetter__("onwritestart", function(val){this.writer.onwritestart=val;});
this.__defineSetter__("onprogress", function(val){this.writer.onprogress=val;});
this.__defineSetter__("onabort", function(val){this.writer.onabort=val;});
this.__defineSetter__("onwrite", function(val){this.writer.onwrite=val;});
this.__defineSetter__("onerror", function(val){this.writer.onerror=val;});
this.__defineSetter__("onwriteend", function(val){this.writer.onwriteend=val;});
// FileWriter
this.__defineGetter__("position", function(){return this.writer.position;});
this.__defineGetter__("length", function(){return this.writer.length;});
this.write = function(data) {
this.writer.write(new Blob([data], {type : "text/plain;charset=UTF-8"}));
};
this.seek = function(offset) {
this.writer.seek(offset);
};
this.truncate = function(size) {
this.writer.truncate(size);
};
}