From f6cf5f7820c0b5e3da8f45246d50af6bfd76768c Mon Sep 17 00:00:00 2001 From: Michael Mrowetz Date: Tue, 14 Mar 2017 22:30:52 +0900 Subject: [PATCH] make unzip-progress status available as callback - remove progress console log. --- README.md | 6 +++++- src/index.html | 2 ++ src/ts/file-reader.ts | 9 +++++---- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 569fa10d..8b5517aa 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ If `selectedPage` is larger than the number of pages the last page will be selec If set a legend explaining the waterfall colours is rendered in the `legendHolder` DOM element. ## `*.zhar` - zipped HAR files -By loading `/perf-cascade-file-reader.min.js` as in [this example](https://github.com/micmro/PerfCascade/blob/master/src/index.html#L78-L84) you can use `perfCascadeFileReader.readFile` to read a zip file and convert it to a JSON HAR object. +By loading `/perf-cascade-file-reader.min.js` as in [this example](https://github.com/micmro/PerfCascade/blob/master/src/index.html#L78-L86) you can use `perfCascadeFileReader.readFile` to read a zip file and convert it to a JSON HAR object. ```javascript perfCascadeFileReader.readFile(fileFromTheFileInput, fileName, function(error, data){ @@ -87,6 +87,10 @@ perfCascadeFileReader.readFile(fileFromTheFileInput, fileName, function(error, d }) ``` +Optionally `perfCascadeFileReader.readFile` also takes a callback (`(progress:number) => void`) as a forth argument +that gets called whenever a new unzip progress status is available. + + ## Dev - Start live-reload server and Typescript compiler with watch: `npm run watch` - Create uglified version: `npm run build` (not tracked ITM) diff --git a/src/index.html b/src/index.html index 04fb28b0..3806c941 100644 --- a/src/index.html +++ b/src/index.html @@ -81,6 +81,8 @@

WPT HAR

} else { renderPerfCascadeChart(data) } + }, function(progress) { + console.log("unzip progress: ", progress / 100, "%"); }) } diff --git a/src/ts/file-reader.ts b/src/ts/file-reader.ts index 9ceec190..19b2874b 100644 --- a/src/ts/file-reader.ts +++ b/src/ts/file-reader.ts @@ -6,7 +6,10 @@ declare const zip: any; zip.useWebWorkers = false; /** handle client side file upload */ -export function readFile(file: File, fileName: string, callback: (e: Error, har?: Har) => void) { +export function readFile(file: File, + fileName: string, + callback: (e: Error, har?: Har) => void, + onProgress?: (progress: number) => void) { if (!file) { return callback(new Error("Failed to load HAR file")); } @@ -30,9 +33,7 @@ export function readFile(file: File, fileName: string, callback: (e: Error, har? parseJson(txt); // close the zip reader zipReader.close(); - }, (progress: number) => { - console.log(`unzip progress: ${progress / 100}%`); - }); + }, onProgress); }); }); } else {