Skip to content

Commit

Permalink
using jszip
Browse files Browse the repository at this point in the history
  • Loading branch information
onlyutkarsh committed Oct 19, 2019
1 parent bbaede5 commit 42bf2a1
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 77 deletions.
1 change: 1 addition & 0 deletions images/dark/svg.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions images/light/svg.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 45 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
},
"devDependencies": {
"@types/glob": "^7.1.1",
"@types/jszip": "~3.1.6",
"@types/mocha": "^5.2.7",
"@types/node": "^10.14.22",
"@types/vscode": "^1.25.0",
Expand All @@ -93,7 +94,7 @@
"webpack-cli": "~3.3.9"
},
"dependencies": {
"node-stream-zip": "~1.8.2",
"jszip": "~3.2.2",
"vscode-extension-telemetry": "~0.1.2"
}
}
49 changes: 22 additions & 27 deletions src/vsixOutlineProvider.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/// <reference path="../types/node-stream-zip.d.ts" />
import * as vscode from 'vscode';
import * as streamzip from "node-stream-zip";
import Util from "./util";
import { TreeItemCollapsibleState } from "vscode";
import * as path from "path";
import { VsixItem } from "./vsixItem";
import * as fs from "fs";
import TelemetryClient from './telemetryClient';
import * as jszip from "jszip";


export class VsixOutlineProvider implements vscode.TreeDataProvider<VsixItem>{
Expand Down Expand Up @@ -99,49 +98,45 @@ export class VsixOutlineProvider implements vscode.TreeDataProvider<VsixItem>{
}

async parseVsix(selectedItem: string): Promise<VsixItem> {
let that = this;
let fileName = path.basename(this._vsixPath);

return vscode.window.withProgress({
location: vscode.ProgressLocation.Notification,
title: `Scanning ${fileName}`,
}, (progress, token) => {
Util.instance.log(`Selected item: ${selectedItem}`);
const zip = new streamzip({
file: selectedItem,
storeEntries: true
});

let root = new VsixItem(fileName, TreeItemCollapsibleState.Expanded);
root.tooltip = this._vsixPath;
root.iconType = "vsix";
root.iconPath = this.getIcon(root.iconType);
return new Promise<VsixItem>((resolve, reject) => {
zip.on("ready", () => {
try {
fs.readFile(this._vsixPath, function (err, data) {
if (err) {
Util.instance.log('Error occurred while reading VSIX');
Util.instance.log(err.message);
TelemetryClient.instance.sendError(err);
reject(err);
}
jszip.loadAsync(data, {
createFolders: true
}).then(zip => {
let files = Object.keys(zip.files);
let startTime = Date.now();
Util.instance.log('Entries read: ' + zip.entriesCount);
let entries = zip.entries();
for (const entry of Object.values(entries)) {
Util.instance.log(`Entry ${entry.name}`);
let path = entry.name.split("/").filter(v => {
Util.instance.log(`Entries read: ${files.length}`);
files.forEach(entry => {
let file = zip.files[entry];
Util.instance.log(`Entry ${file}`);
let path = file.name.split("/").filter(v => {
return v && v.length > 0;
});
this.buildTree(root, path, entry.isDirectory, 0);
}
zip.close();

TelemetryClient.instance.sendEvent("vsixParsedTime", {
that.buildTree(root, path, file.dir, 0);
});
TelemetryClient.instance.sendEvent("vsixParsingTime", {
["totalSecondsParsing"]: ((Date.now() - startTime) / 1000).toString()
});

resolve(root);
}
catch (err) {
Util.instance.log('Error occurred');
Util.instance.log(err);
TelemetryClient.instance.sendError(err);
reject(err);
}
});
});
});
});
Expand Down
28 changes: 0 additions & 28 deletions types/node-stream-zip.d.ts

This file was deleted.

0 comments on commit 42bf2a1

Please sign in to comment.