Skip to content

Commit

Permalink
Lazy reference zip.js
Browse files Browse the repository at this point in the history
This change will allow a commonJs environment build,
where zip.js is loaded later then perf-cascade import itself
  • Loading branch information
ypetya committed Sep 3, 2018
1 parent 23ca585 commit 7713260
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/ts/file-reader.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Har } from "har-format";

declare const zip: any;

// use zip
zip.useWebWorkers = false;
const getConfiguredZipJs = () => {
const zip = window["zip"] || {};
zip.useWebWorkers = false;
return zip;
};

/** handle client side file upload */
export function readFile(file: File,
Expand All @@ -25,6 +27,8 @@ export function readFile(file: File,

/** start reading the file */
const extension = (fileName.match(/\.[0-9a-z]+$/i) || [])[0];
const zip = getConfiguredZipJs();

if ([".zhar", ".zip"].indexOf(extension) !== -1) {
/** zhar */
zip.createReader(new zip.BlobReader(file), (zipReader) => {
Expand Down

0 comments on commit 7713260

Please sign in to comment.