| 475 | } |
| 476 | |
| 477 | class FileDigester { |
| 478 | |
| 479 | constructor(meta, callback) { |
| 480 | this._buffer = []; |
| 481 | this._bytesReceived = 0; |
| 482 | this._size = meta.size; |
| 483 | this._mime = meta.mime || 'application/octet-stream'; |
| 484 | this._name = meta.name; |
| 485 | this._callback = callback; |
| 486 | } |
| 487 | |
| 488 | unchunk(chunk) { |
| 489 | this._buffer.push(chunk); |
| 490 | this._bytesReceived += chunk.byteLength || chunk.size; |
| 491 | const totalChunks = this._buffer.length; |
| 492 | this.progress = this._bytesReceived / this._size; |
| 493 | if (isNaN(this.progress)) this.progress = 1 |
| 494 | |
| 495 | if (this._bytesReceived < this._size) return; |
| 496 | // we are done |
| 497 | let blob = new Blob(this._buffer, { type: this._mime }); |
| 498 | this._callback({ |
| 499 | name: this._name, |
| 500 | mime: this._mime, |
| 501 | size: this._size, |
| 502 | blob: blob |
| 503 | }); |
| 504 | } |
| 505 | |
| 506 | } |
| 507 | |
| 508 | class Events { |
| 509 | static fire(type, detail) { |
nothing calls this directly
no outgoing calls
no test coverage detected