Ingen beskrivning

FileReader.js 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Copyright 2016 wkh237@github. All rights reserved.
  2. // Use of this source code is governed by a MIT-style license that can be
  3. // found in the LICENSE file.
  4. import ProgressEvent from './ProgressEvent.js'
  5. import EventTarget from './EventTarget'
  6. import Blob from './Blob'
  7. import Log from '../utils/log.js'
  8. import fs from '../fs'
  9. const log = new Log('FileReader')
  10. log.level(3)
  11. export default class FileReader extends EventTarget {
  12. static get EMPTY(){
  13. return 0
  14. }
  15. static get LOADING(){
  16. return 1
  17. }
  18. static get DONE(){
  19. return 2
  20. }
  21. // properties
  22. _readState:number = 0;
  23. _result:any;
  24. _error:any;
  25. get isRNFBPolyFill(){ return true }
  26. // event handlers
  27. onloadstart:(e:Event) => void;
  28. onprogress:(e:Event) => void;
  29. onload:(e:Event) => void;
  30. onabort:(e:Event) => void;
  31. onerror:(e:Event) => void;
  32. onloadend:(e:Event) => void;
  33. constructor() {
  34. super()
  35. log.verbose('file reader const')
  36. this._result = null
  37. }
  38. abort() {
  39. log.verbose('abort')
  40. }
  41. readAsArrayBuffer(b:Blob) {
  42. log.verbose('readAsArrayBuffer', b)
  43. }
  44. readAsBinaryString(b:Blob) {
  45. log.verbose('readAsBinaryString', b)
  46. }
  47. readAsText(b:Blob, label:?string) {
  48. log.verbose('readAsText', b, label)
  49. }
  50. readAsDataURL(b:Blob) {
  51. log.verbose('readAsDataURL', b)
  52. }
  53. dispatchEvent(event, e) {
  54. log.verbose('dispatch event', event, e)
  55. super.dispatchEvent(event, e)
  56. if(typeof this[`on${event}`] === 'function') {
  57. this[`on${event}`](e)
  58. }
  59. }
  60. // private methods
  61. // getters and setters
  62. get readyState() {
  63. return this._readyState
  64. }
  65. get result() {
  66. return this._result
  67. }
  68. }