Bez popisu

FileReader.js 1.7KB

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