Skip to content

Commit

Permalink
make unzip-progress status available as callback
Browse files Browse the repository at this point in the history
- remove progress console log.
  • Loading branch information
Michael Mrowetz committed Mar 14, 2017
1 parent 489ac54 commit f6cf5f7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ <h1>WPT HAR</h1>
} else {
renderPerfCascadeChart(data)
}
}, function(progress) {
console.log("unzip progress: ", progress / 100, "%");
})
}

Expand Down
9 changes: 5 additions & 4 deletions src/ts/file-reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
Expand All @@ -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 {
Expand Down

0 comments on commit f6cf5f7

Please sign in to comment.