()
| 215 | } |
| 216 | |
| 217 | private registerUserEvents () { |
| 218 | if ( this.registeredEvents.size > 0 ) { |
| 219 | return |
| 220 | } |
| 221 | |
| 222 | const userEvents: Array<[ FileReaderEventName, 'onloadstart' | 'onprogress' | 'onload' | 'onloadend' | 'onabort' ]> = [ |
| 223 | [ 'loadstart', 'onloadstart' ], |
| 224 | [ 'progress', 'onprogress' ], |
| 225 | [ 'load', 'onload' ], |
| 226 | [ 'loadend', 'onloadend' ], |
| 227 | [ 'abort', 'onabort' ] |
| 228 | ] |
| 229 | |
| 230 | for ( const [ eventName, propertyName ] of userEvents ) { |
| 231 | this.emitter.on( eventName, ( event?: FileReaderEventPayload ) => { |
| 232 | invokeIfFunction( this[ propertyName ], [ event ], this ) |
| 233 | } ) |
| 234 | this.registeredEvents.add( eventName ) |
| 235 | } |
| 236 | |
| 237 | this.emitter.on( 'error', ( event?: FileReaderEventPayload ) => { |
| 238 | if ( typeof this.onerror === 'function' ) { |
| 239 | this.onerror( event ) |
| 240 | return |
| 241 | } |
| 242 | |
| 243 | const error = ( event as FileReaderErrorEvent | undefined )?.target.error |
| 244 | |
| 245 | if ( error && this.emitter.listenerCount( 'error' ) <= 1 ) { |
| 246 | throw error |
| 247 | } |
| 248 | } ) |
| 249 | this.registeredEvents.add( 'error' ) |
| 250 | } |
| 251 | |
| 252 | private mapStreamToEmitter () { |
| 253 | const stream = this.fileStream |
no test coverage detected