UNPKG

1.94 kBJavaScriptView Raw
1/***************************************************************************************
2 * (c) 2017 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 ****************************************************************************************/
12
13const yauzl = require('yauzl');
14
15module.exports = (zipPath) => {
16 return new Promise((resolve, reject) => {
17 yauzl.open(zipPath, { lazyEntries: true }, (error, zipFile) => {
18 if (error) {
19 reject(new Error(`Error inspecting zip file for extension info. ${error}`));
20 return;
21 }
22
23 zipFile.readEntry();
24 zipFile.on('entry', (entry) => {
25 if (entry.fileName === 'extension.json') {
26 zipFile.openReadStream(entry, (err, readStream) => {
27 const chunks = [];
28
29 readStream.on('data', chunk => chunks.push(chunk));
30 readStream.on('end', () => {
31 const manifest = JSON.parse(Buffer.concat(chunks).toString());
32 resolve(manifest);
33 zipFile.close();
34 });
35 });
36 } else {
37 zipFile.readEntry();
38 }
39 });
40 zipFile.on('end', () => {
41 reject(new Error('No extension.json found within the extension package zip file.'));
42 });
43 zipFile.on('error', (error) => {
44 reject(new Error(`Error inspecting zip file for extension info. ${error}`));
45 });
46 });
47 })
48};