-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathjarContentProvider.ts
29 lines (25 loc) · 1.05 KB
/
jarContentProvider.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import * as fs from 'fs';
import * as os from 'os';
import * as vscode from 'vscode';
import * as JSZip from 'jszip';
export class JarContentProvider implements vscode.TextDocumentContentProvider {
public provideTextDocumentContent(uri: vscode.Uri, token: vscode.CancellationToken): Thenable<string> {
return new Promise<string>((resolve, reject) => {
let rawPath = uri.path;
let pathToFileInJar = rawPath.slice(rawPath.search('!/') + 2);
let pathToJar = rawPath.slice('file:'.length);
pathToJar = pathToJar.slice(0, pathToJar.search('!'));
if (os.platform() === 'win32') {
pathToJar = pathToJar.replace(/\//g, '\\').slice(1);
}
fs.readFile(pathToJar, (err, data) => {
let zip = new JSZip();
zip.loadAsync(data).then((new_zip) => {
new_zip.file(pathToFileInJar)?.async("text").then((value) => {
resolve(value);
})
})
})
});
}
}