1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.readVSIXPackage = exports.readZip = void 0;
|
4 | const yauzl_1 = require("yauzl");
|
5 | const xml_1 = require("./xml");
|
6 | async function bufferStream(stream) {
|
7 | return await new Promise((c, e) => {
|
8 | const buffers = [];
|
9 | stream.on('data', buffer => buffers.push(buffer));
|
10 | stream.once('error', e);
|
11 | stream.once('end', () => c(Buffer.concat(buffers)));
|
12 | });
|
13 | }
|
14 | async function readZip(packagePath, filter) {
|
15 | const zipfile = await new Promise((c, e) => (0, yauzl_1.open)(packagePath, { lazyEntries: true }, (err, zipfile) => (err ? e(err) : c(zipfile))));
|
16 | return await new Promise((c, e) => {
|
17 | const result = new Map();
|
18 | zipfile.once('close', () => c(result));
|
19 | zipfile.readEntry();
|
20 | zipfile.on('entry', (entry) => {
|
21 | const name = entry.fileName.toLowerCase();
|
22 | if (filter(name)) {
|
23 | zipfile.openReadStream(entry, (err, stream) => {
|
24 | if (err) {
|
25 | zipfile.close();
|
26 | return e(err);
|
27 | }
|
28 | bufferStream(stream).then(buffer => {
|
29 | result.set(name, buffer);
|
30 | zipfile.readEntry();
|
31 | });
|
32 | });
|
33 | }
|
34 | else {
|
35 | zipfile.readEntry();
|
36 | }
|
37 | });
|
38 | });
|
39 | }
|
40 | exports.readZip = readZip;
|
41 | async function readVSIXPackage(packagePath) {
|
42 | const map = await readZip(packagePath, name => /^extension\/package\.json$|^extension\.vsixmanifest$/i.test(name));
|
43 | const rawManifest = map.get('extension/package.json');
|
44 | if (!rawManifest) {
|
45 | throw new Error('Manifest not found');
|
46 | }
|
47 | const rawXmlManifest = map.get('extension.vsixmanifest');
|
48 | if (!rawXmlManifest) {
|
49 | throw new Error('VSIX manifest not found');
|
50 | }
|
51 | return {
|
52 | manifest: JSON.parse(rawManifest.toString('utf8')),
|
53 | xmlManifest: await (0, xml_1.parseXmlManifest)(rawXmlManifest.toString('utf8')),
|
54 | };
|
55 | }
|
56 | exports.readVSIXPackage = readVSIXPackage;
|
57 |
|
\ | No newline at end of file |