From 0ec2b387d0b5a87e4aba1b19b69ac08fc99cde77 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 4 Apr 2018 17:55:17 +0800 Subject: [PATCH] FileReader API fix. --- jsb/builtin/jsb-adapter/FileReader.js | 32 ++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/jsb/builtin/jsb-adapter/FileReader.js b/jsb/builtin/jsb-adapter/FileReader.js index 6f49201fc6..dabc8b7f44 100755 --- a/jsb/builtin/jsb-adapter/FileReader.js +++ b/jsb/builtin/jsb-adapter/FileReader.js @@ -23,12 +23,32 @@ THE SOFTWARE. ****************************************************************************/ -/* - * TODO 使用 wx.readFile 来封装 FileReader - */ -class FileReader { - construct() { - } +const EventTarget = require('./EventTarget') + +class FileReader extends EventTarget { + construct() { + this.result = null + + } + + // Aborts the read operation. Upon return, the readyState will be DONE. + abort() {} + + // Starts reading the contents of the specified Blob, once finished, the result attribute contains an ArrayBuffer representing the file's data. + readAsArrayBuffer() { + + } + + // Starts reading the contents of the specified Blob, once finished, the result attribute contains a data: URL representing the file's data. + readAsDataURL(blob) { + this.result = 'data:image/png;base64,' + window.btoa(blob); + this.onload(); + } + + // Starts reading the contents of the specified Blob, once finished, the result attribute contains the contents of the file as a text string. + readAsText() { + + } } module.exports = FileReader;