-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor the BulkFileUploader in preparation of the coming changes
issue #67
- Loading branch information
1 parent
330bd18
commit 11c4d5a
Showing
6 changed files
with
135 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright 2018 Simon Edwards <[email protected]> | ||
* | ||
* This source code is licensed under the MIT license which is detailed in the LICENSE.txt file. | ||
*/ | ||
import {Event} from 'extraterm-extension-api'; | ||
import {Transform} from 'stream'; | ||
|
||
import {DebouncedDoLater} from './DoLater'; | ||
import {EventEmitter} from './EventEmitter'; | ||
|
||
|
||
const DEBOUNCE_DELAY_MILLIS = 100; | ||
|
||
|
||
/** | ||
* Stream transform which emits events signaling the amount of data which | ||
* has passed through. | ||
*/ | ||
export class ByteCountingStreamTransform extends Transform { | ||
|
||
private _counter = 0; | ||
private _doLater: DebouncedDoLater = null; | ||
private _onCountUpdateEventEmitter = new EventEmitter<number>(); | ||
|
||
onCountUpdate: Event<number>; | ||
|
||
constructor(options?) { | ||
super(options); | ||
this.onCountUpdate = this._onCountUpdateEventEmitter.event; | ||
|
||
this._doLater = new DebouncedDoLater(() => { | ||
this._onCountUpdateEventEmitter.fire(this.getCount()); | ||
}, DEBOUNCE_DELAY_MILLIS); | ||
} | ||
|
||
protected _transform(chunk: any, encoding: string, callback: Function): void { | ||
this._counter += chunk.length; | ||
this.push(chunk); | ||
this._doLater.trigger(); | ||
callback(); | ||
} | ||
|
||
protected _flush(callback: Function): void { | ||
this._doLater.doNow(); | ||
callback(); | ||
} | ||
|
||
getCount(): number { | ||
return this._counter; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters