-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #547 from libarchive
- Loading branch information
Showing
23 changed files
with
547 additions
and
412 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
15 changes: 15 additions & 0 deletions
15
public/vendor/libarchive.js-1.3.0/dist/wasm-gen/libarchive.js
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
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,69 @@ | ||
import Observable from 'bemuse/utils/observable' | ||
|
||
interface IProgressFormatter { | ||
(progress: Progress): string | ||
} | ||
|
||
/** | ||
* The Progress class represents the progress of an asynchronous operation. | ||
* It is inspired by C#'s IProgress interface. | ||
* | ||
* See: http://blogs.msdn.com/b/dotnet/archive/2012/06/06/async-in-4-5-enabling-progress-and-cancellation-in-async-apis.aspx | ||
*/ | ||
export class Progress { | ||
/** The current progress (out of `Progress#total`). */ | ||
public current: number | undefined = undefined | ||
/** Total progress value */ | ||
public total: number | undefined = undefined | ||
/** Some arbitrary information associated with this Progress. */ | ||
public extra: any | ||
/** | ||
* The formatter of this progress. This formatter will be used to compute | ||
* the text representation of this progress (`Progress#toString`). | ||
*/ | ||
public formatter?: IProgressFormatter | ||
private _observable = new Observable<void>() | ||
/** | ||
* Updates the progress. | ||
*/ | ||
report(current: number, total: number, extra?: any) { | ||
this.current = current | ||
this.total = total | ||
this.extra = extra | ||
this._observable.notify() | ||
} | ||
/** | ||
* Attaches a progress listener function to this progress. | ||
* The function `f` will be called immediately and synchronously upon watching, | ||
* and will be called when the progress value is updated. | ||
* @param f | ||
* @returns a function that, when called, unsubscribes this listener. | ||
*/ | ||
watch(f: (progress: Progress) => void) { | ||
f(this) | ||
return this._observable.watch(() => f(this)) | ||
} | ||
/** | ||
* The current progress as a fraction (out of 1). | ||
*/ | ||
get progress() { | ||
if (this.total && this.current !== undefined && this.current !== null) { | ||
return this.current / this.total | ||
} else { | ||
return null | ||
} | ||
} | ||
/** | ||
* Returns a string representation of this progress instance. | ||
* This method is used for displaying the progress as a text. | ||
*/ | ||
toString() { | ||
if (this.formatter !== undefined) { | ||
return this.formatter(this) | ||
} else if (this.progress !== null) { | ||
return this.current + ' / ' + this.total | ||
} else { | ||
return '' | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,77 +1,4 @@ | ||
// !! avoid external dependencies since this is used in boot script! | ||
|
||
import Observable from 'bemuse/utils/observable' | ||
|
||
interface IProgressFormatter { | ||
(progress: Progress): string | ||
} | ||
|
||
/** | ||
* The Progress class represents the progress of an asynchronous operation. | ||
* It is inspired by C#'s IProgress interface. | ||
* | ||
* See: http://blogs.msdn.com/b/dotnet/archive/2012/06/06/async-in-4-5-enabling-progress-and-cancellation-in-async-apis.aspx | ||
*/ | ||
export class Progress { | ||
/** The current progress (out of `Progress#total`). */ | ||
public current: number | undefined = undefined | ||
/** Total progress value */ | ||
public total: number | undefined = undefined | ||
/** Some arbitrary information associated with this Progress. */ | ||
public extra: any | ||
/** | ||
* The formatter of this progress. This formatter will be used to compute | ||
* the text representation of this progress (`Progress#toString`). | ||
*/ | ||
public formatter?: IProgressFormatter | ||
private _observable = new Observable<void>() | ||
|
||
/** | ||
* Updates the progress. | ||
*/ | ||
report(current: number, total: number, extra: any) { | ||
this.current = current | ||
this.total = total | ||
this.extra = extra | ||
this._observable.notify() | ||
} | ||
|
||
/** | ||
* Attaches a progress listener function to this progress. | ||
* The function `f` will be called immediately and synchronously upon watching, | ||
* and will be called when the progress value is updated. | ||
* @param f | ||
* @returns a function that, when called, unsubscribes this listener. | ||
*/ | ||
watch(f: (progress: Progress) => void) { | ||
f(this) | ||
return this._observable.watch(() => f(this)) | ||
} | ||
|
||
/** | ||
* The current progress as a fraction (out of 1). | ||
*/ | ||
get progress() { | ||
if (this.total && this.current !== undefined && this.current !== null) { | ||
return this.current / this.total | ||
} else { | ||
return null | ||
} | ||
} | ||
|
||
/** | ||
* Returns a string representation of this progress instance. | ||
* This method is used for displaying the progress as a text. | ||
*/ | ||
toString() { | ||
if (this.formatter !== undefined) { | ||
return this.formatter(this) | ||
} else if (this.progress !== null) { | ||
return this.current + ' / ' + this.total | ||
} else { | ||
return '' | ||
} | ||
} | ||
} | ||
|
||
import { Progress } from './Progress' | ||
export default Progress |
This file was deleted.
Oops, something went wrong.
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,93 @@ | ||
import { BYTES_FORMATTER } from 'bemuse/progress/formatters' | ||
import { Progress } from './Progress' | ||
|
||
/** | ||
* Returns a callback that, when called, | ||
* update the progress with increasing `current` value, | ||
* out of a fixed `total`. | ||
*/ | ||
export function fixed(total: number, progress: Progress) { | ||
if (!progress) return () => {} | ||
let loaded = 0 | ||
progress.report(0, total) | ||
return (extra: any) => progress.report(++loaded, total, extra) | ||
} | ||
|
||
/** | ||
* Updates the progress with the result of an atomic operation. | ||
*/ | ||
export function atomic<T>( | ||
progress: Progress, | ||
promise: PromiseLike<T> | ||
): PromiseLike<T> { | ||
if (!progress) return promise | ||
return Promise.resolve(promise).tap(data => { | ||
if (hasByteLength(data)) { | ||
progress.formatter = BYTES_FORMATTER | ||
progress.report(data.byteLength, data.byteLength) | ||
} else { | ||
progress.report(1, 1) | ||
} | ||
}) | ||
} | ||
function hasByteLength(data: any): data is { byteLength: number } { | ||
return data && data.byteLength | ||
} | ||
|
||
/** | ||
* Wraps an async function that may be called multiple times. | ||
* Each call adds to the total, and each async resolution adds to current. | ||
*/ | ||
export function wrapPromise<A extends any[], R>( | ||
progress: Progress, | ||
f: (...args: A) => PromiseLike<R> | ||
): (...args: A) => PromiseLike<R> { | ||
let current = 0 | ||
let total = 0 | ||
return function(this: any, ...args: A) { | ||
progress.report(current, ++total) | ||
return Promise.resolve(f.apply(this, args)).tap(() => | ||
progress.report(++current, total) | ||
) | ||
} | ||
} | ||
|
||
export function bind(from: Progress, to: Progress) { | ||
return from.watch(() => to.report(from.current!, from.total!, from.extra)) | ||
} | ||
|
||
/** | ||
* Updates the `target` with progress data from multiple sources. | ||
*/ | ||
export function simultaneous(target: Progress) { | ||
let queue: Progress[] = [] | ||
let current: Progress | undefined | ||
let unsubscribe: (() => void) | null = null | ||
function update() { | ||
if (current) { | ||
target.report(current.current!, current.total!, current.extra) | ||
} | ||
if (queue.length > 0 && (!current || current.progress! >= 1)) { | ||
bind(queue.shift()!) | ||
} | ||
} | ||
function bind(progress: Progress) { | ||
if (current === progress) { | ||
return | ||
} | ||
if (unsubscribe) { | ||
unsubscribe() | ||
unsubscribe = null | ||
} | ||
current = progress | ||
if (current) { | ||
unsubscribe = current.watch(update) | ||
} | ||
} | ||
return { | ||
add(progress: Progress) { | ||
queue.push(progress) | ||
update() | ||
}, | ||
} | ||
} |
Oops, something went wrong.