This commit is contained in:
Tutur33
2023-11-24 22:35:41 +01:00
parent 3c0b507a93
commit 7644b2a0f7
45165 changed files with 4803356 additions and 3 deletions
+35
View File
@@ -0,0 +1,35 @@
'use strict';
const EventEmitter = require('events');
const writtenBytes = new WeakMap();
class ProgressEmitter extends EventEmitter {
constructor(sourcePath, destinationPath) {
super();
this._sourcePath = sourcePath;
this._destinationPath = destinationPath;
}
get writtenBytes() {
return writtenBytes.get(this);
}
set writtenBytes(value) {
writtenBytes.set(this, value);
this.emitProgress();
}
emitProgress() {
const {size, writtenBytes} = this;
this.emit('progress', {
sourcePath: this._sourcePath,
destinationPath: this._destinationPath,
size,
writtenBytes,
percent: writtenBytes === size ? 1 : writtenBytes / size
});
}
}
module.exports = ProgressEmitter;