Skip to content

Commit

Permalink
Change zip lib
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlambchop committed Dec 19, 2024
1 parent 145c236 commit 9c9feb3
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 13 deletions.
34 changes: 33 additions & 1 deletion npm-shrinkwrap.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 @@ -80,7 +80,8 @@
"verror": "^1.10.0",
"wiring-preprocessor": "^2.2.0",
"xtend": "^4.0.2",
"yargs": "^5.0.0"
"yargs": "^5.0.0",
"yauzl": "^3.2.0"
},
"devDependencies": {
"chai": "^4.2.0",
Expand Down
54 changes: 43 additions & 11 deletions src/cmd/flash.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ const {
} = require('../lib/flash-helper');
const createApiCache = require('../lib/api-cache');
const { validateDFUSupport } = require('./device-util');
const unzip = require('unzipper');
//const unzip = require('unzipper');
const yauzl = require('yauzl');
const qdl = require('../lib/qdl');

const TACHYON_MANIFEST_FILE = 'manifest.json';
Expand Down Expand Up @@ -164,16 +165,47 @@ module.exports = class FlashCommand extends CLICommandBase {
return JSON.parse(manifestFile);
}

async _loadManifestFromZip(zipPath) {
const dir = await unzip.Open.file(zipPath);
const manifestFile = dir.files.find(file => file.path === TACHYON_MANIFEST_FILE);
if (!manifestFile) {
throw new Error(`Unable to find ${TACHYON_MANIFEST_FILE}${os.EOL}`);
}

const manifest = await manifestFile.buffer();
return JSON.parse(manifest.toString());
}
async _loadManifestFromZip(zipPath) {
return new Promise((resolve, reject) => {
yauzl.open(zipPath, { lazyEntries: true }, (err, zipfile) => {
if (err) return reject(err);

let found = false;

zipfile.on('entry', entry => {
if (entry.fileName === TACHYON_MANIFEST_FILE) {
found = true;

zipfile.openReadStream(entry, (err, readStream) => {
if (err) return reject(err);

const chunks = [];
readStream.on('data', chunk => chunks.push(chunk));
readStream.on('end', () => {
zipfile.close();
try {
const manifest = Buffer.concat(chunks).toString();
resolve(JSON.parse(manifest));
} catch (parseError) {
reject(new Error(`Failed to parse manifest JSON: ${parseError.message}`));
}
});
});
} else {
zipfile.readEntry();
}
});

zipfile.on('end', () => {
if (!found) {
reject(new Error(`Unable to find ${manifestFileName}`));
}
});

zipfile.readEntry();
});
});
}

_parseManfiestData(data) {
return {
Expand Down

0 comments on commit 9c9feb3

Please sign in to comment.