Skip to content

Commit

Permalink
update zip.js to 2.7.6
Browse files Browse the repository at this point in the history
Also add support for updating files in dist/vendor during build step.
  • Loading branch information
octocorvus authored and thestinger committed Apr 22, 2023
1 parent b21126d commit 2ca0b56
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"author": "Danny Lin <[email protected]>",
"license": "MIT",
"dependencies": {
"@zip.js/zip.js": "2.2.27"
"@zip.js/zip.js": "^2.7.6"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.0.2",
Expand All @@ -22,7 +22,7 @@
"typescript": "^5.0.4"
},
"scripts": {
"build": "rollup -c"
"build": "rollup -c && cp node_modules/@zip.js/zip.js/dist/z-worker-pako.js dist/vendor"
},
"files": [
"dist/fastboot.*"
Expand Down
40 changes: 24 additions & 16 deletions src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
TextWriter,
Entry,
EntryGetDataOptions,
Writer,
WritableWriter,
} from "@zip.js/zip.js";
import { FastbootDevice, FastbootError, ReconnectCallback } from "./fastboot";

Expand Down Expand Up @@ -68,11 +68,11 @@ const FASTBOOTD_REBOOT_TIME = 16000; // ms
const USERDATA_ERASE_TIME = 1000; // ms

// Wrapper for Entry#getData() that unwraps ProgressEvent errors
async function zipGetData(
async function zipGetData<Type>(
entry: Entry,
writer: Writer,
writer: WritableWriter,
options?: EntryGetDataOptions,
) {
): Promise<Type> {
try {
return await entry.getData!(writer, options);
} catch (e) {
Expand All @@ -94,15 +94,19 @@ async function flashEntryBlob(
onProgress: FactoryProgressCallback,
partition: string
) {
common.logDebug(`Unpacking ${partition}`);
onProgress("unpack", partition, 0.0);
let blob = await zipGetData(
let blob: Blob = await zipGetData(
entry,
new BlobWriter("application/octet-stream"),
{
onprogress: (bytes: number, len: number) => {
onProgress("unpack", partition, bytes / len);
onstart(total: number): Promise<void> | undefined {
common.logDebug(`Unpacking ${partition} (${total} bytes)`);
onProgress("unpack", partition, 0.0);
return;
},
onprogress(progress: number, total: number): Promise<void> | undefined {
onProgress("unpack", partition, progress / total);
return;
}
}
);

Expand Down Expand Up @@ -271,16 +275,20 @@ export async function flashZip(
}

// Load nested images for the following steps
common.logDebug("Loading nested images from zip");
onProgress("unpack", "images", 0.0);
let entry = entries.find((e) => e.filename.match(/image-.+\.zip$/));
let imagesBlob = await zipGetData(
let imagesBlob: Blob = await zipGetData(
entry!,
new BlobWriter("application/zip"),
{
onprogress: (bytes: number, len: number) => {
onProgress("unpack", "images", bytes / len);
onstart(total: number): Promise<void> | undefined {
common.logDebug(`Loading nested images from zip (${total} bytes)`);
onProgress("unpack", "images", 0.0);
return;
},
onprogress(progress: number, total: number): Promise<void> | undefined {
onProgress("unpack", "images", progress / total);
return;
}
}
);
let imageReader = new ZipReader(new BlobReader(imagesBlob));
Expand All @@ -289,7 +297,7 @@ export async function flashZip(
// 3. Check requirements
entry = imageEntries.find((e) => e.filename === "android-info.txt");
if (entry !== undefined) {
let reqText = await zipGetData(entry, new TextWriter());
let reqText: string = await zipGetData(entry, new TextWriter());
await checkRequirements(device, reqText);
}

Expand Down Expand Up @@ -320,7 +328,7 @@ export async function flashZip(

let superAction = wipe ? "wipe" : "flash";
onProgress(superAction, "super", 0.0);
let superBlob = await zipGetData(
let superBlob: Blob = await zipGetData(
entry,
new BlobWriter("application/octet-stream")
);
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@
resolved "https://registry.yarnpkg.com/@types/w3c-web-usb/-/w3c-web-usb-1.0.6.tgz#5d8560d0d9f585ffc80865bc773db7bc975b680c"
integrity sha512-cSjhgrr8g4KbPnnijAr/KJDNKa/bBa+ixYkywFRvrhvi9n1WEl7yYbtRyzE6jqNQiSxxJxoAW3STaOQwJHndaw==

"@zip.js/zip.js@2.2.27":
version "2.2.27"
resolved "https://registry.yarnpkg.com/@zip.js/zip.js/-/zip.js-2.2.27.tgz#672c63fd586d83c6f6c6231a38b54a16b5abe267"
integrity sha512-lQLsq41xUIGJnUizICgjLL+1hrnlLcqyWnQcaNi8FdsxfJl8y0bqdolDit8o65Huai+/GwXbCODMVu05kNU8mA==
"@zip.js/zip.js@^2.7.6":
version "2.7.6"
resolved "https://registry.yarnpkg.com/@zip.js/zip.js/-/zip.js-2.7.6.tgz#76dfa2f36780f6a2a34ef7979f4464063ffe1ca7"
integrity sha512-j9gaYG84Qd3tI3X7BiOpL5bckbbAetpxtpilKnSyW5rMTnrXwH6GtXkL8rEBxnPk100exbfxNlORwFagX7fMfg==

acorn-jsx@^5.3.2:
version "5.3.2"
Expand Down

0 comments on commit 2ca0b56

Please sign in to comment.