From 9c9feb387c0c9d876806fa0b36dca9ffa84b57e6 Mon Sep 17 00:00:00 2001 From: Nick Lambourne Date: Wed, 18 Dec 2024 19:49:25 -0800 Subject: [PATCH] Change zip lib --- npm-shrinkwrap.json | 34 +++++++++++++++++++++++++++- package.json | 3 ++- src/cmd/flash.js | 54 ++++++++++++++++++++++++++++++++++++--------- 3 files changed, 78 insertions(+), 13 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 0f78f4aa0..940b50ba6 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -37,7 +37,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" }, "bin": { "particle": "src/index.js" @@ -6465,6 +6466,11 @@ "through2": "^2.0.3" } }, + "node_modules/pend": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", + "integrity": "sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg==" + }, "node_modules/picomatch": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", @@ -9229,6 +9235,18 @@ "node": ">= 0.10.0" } }, + "node_modules/yauzl": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-3.2.0.tgz", + "integrity": "sha512-Ow9nuGZE+qp1u4JIPvg+uCiUr7xGQWdff7JQSk5VGYTAZMDe2q8lxJ10ygv10qmSj031Ty/6FNJpLO4o1Sgc+w==", + "dependencies": { + "buffer-crc32": "~0.2.3", + "pend": "~1.2.0" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", @@ -14338,6 +14356,11 @@ "through2": "^2.0.3" } }, + "pend": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", + "integrity": "sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg==" + }, "picomatch": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", @@ -16589,6 +16612,15 @@ } } }, + "yauzl": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-3.2.0.tgz", + "integrity": "sha512-Ow9nuGZE+qp1u4JIPvg+uCiUr7xGQWdff7JQSk5VGYTAZMDe2q8lxJ10ygv10qmSj031Ty/6FNJpLO4o1Sgc+w==", + "requires": { + "buffer-crc32": "~0.2.3", + "pend": "~1.2.0" + } + }, "yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", diff --git a/package.json b/package.json index 35b28ee2a..4fdda7161 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/cmd/flash.js b/src/cmd/flash.js index 8b8ad7cda..f4130a50d 100644 --- a/src/cmd/flash.js +++ b/src/cmd/flash.js @@ -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'; @@ -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 {