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CAAC,KAAL,CAAW,KAAK,WAAL,IAAoB,CAAC,GAAG,GAAG,KAAK,KAAZ,IAAqB,IAAzC,CAAX;AALF,SAAhB;AAOA,aAAK,KAAL,GAAa,CAAb;AACD;;AAED,IAAA,QAAQ,CAAC,IAAD,EAAO,KAAP,CAAR;AACD;;AAED,EAAA,MAAM,CAAC,QAAD,EAAc;AAClB,QAAI,KAAK,iBAAL,CAAuB,SAA3B,EAAsC;AACpC,MAAA,QAAQ,CAAC,IAAI,KAAJ,CAAU,WAAV,CAAD,CAAR;AACA;AACD;;AAED,SAAK,UAAL,CAAgB;AACd,MAAA,KAAK,EAAE,KAAK,KADE;AAEd,MAAA,KAAK,EAAE,KAAK,KAFE;AAGd,MAAA,WAAW,EAAE,KAAK,KAHJ;AAId,MAAA,OAAO,EAAE,GAJK;AAKd,MAAA,cAAc,EAAE,IAAI,CAAC,KAAL,CAAW,KAAK,WAAL,IAAoB,CAAC,IAAI,CAAC,GAAL,KAAa,KAAK,KAAnB,IAA4B,IAAhD,CAAX;AALF,KAAhB;AAOA,SAAK,KAAL,GAAa,CAAb;AAEA,IAAA,QAAQ,CAAC,IAAD,CAAR;AACD;;AArDqD,C","sourcesContent":["import { Transform } from \"stream\"\nimport { CancellationToken } from \"./CancellationToken\"\n\nexport interface ProgressInfo {\n total: number\n delta: number\n transferred: number\n percent: number\n bytesPerSecond: number\n}\n\nexport class ProgressCallbackTransform extends Transform {\n private start = Date.now()\n private transferred = 0\n private delta = 0\n\n private nextUpdate = this.start + 1000\n\n constructor(private readonly total: number, private readonly cancellationToken: CancellationToken, private readonly onProgress: (info: ProgressInfo) => any) {\n super()\n }\n\n _transform(chunk: any, encoding: string, callback: any) {\n if (this.cancellationToken.cancelled) {\n callback(new Error(\"Cancelled\"), null)\n return\n }\n\n this.transferred += chunk.length\n this.delta += chunk.length\n\n const now = Date.now()\n if (now >= this.nextUpdate && this.transferred !== this.total /* will be emitted on _flush */) {\n this.nextUpdate = now + 1000\n\n this.onProgress({\n total: this.total,\n delta: this.delta,\n transferred: this.transferred,\n percent: (this.transferred / this.total) * 100,\n bytesPerSecond: Math.round(this.transferred / ((now - this.start) / 1000))\n })\n this.delta = 0\n }\n\n callback(null, chunk)\n }\n\n _flush(callback: any): void {\n if (this.cancellationToken.cancelled) {\n callback(new Error(\"Cancelled\"))\n return\n }\n\n this.onProgress({\n total: this.total,\n delta: this.delta,\n transferred: this.total,\n percent: 100,\n bytesPerSecond: Math.round(this.transferred / ((Date.now() - this.start) / 1000))\n })\n this.delta = 0\n\n callback(null)\n }\n}\n"],"sourceRoot":""}
|