Loading lib/factory.js +34 −12 Original line number Diff line number Diff line Loading @@ -34,14 +34,31 @@ const BOOTLOADER_REBOOT_TIME = 4000; // ms const FASTBOOTD_REBOOT_TIME = 16000; // ms const USERDATA_ERASE_TIME = 1000; // ms // Wrapper for Entry#getData() to unwrap ProgressEvent errors async function zipGetData(entry, writer, options = undefined) { try { return await entry.getData(writer, options); } catch (e) { if (e instanceof ProgressEvent && e.type === "error") { throw e.target.error; } else { throw e; } } } async function flashEntryBlob(device, entry, onProgress, partition) { common.logDebug(`Unpacking ${partition}`); onProgress("unpack", partition, 0.0); let blob = await entry.getData(new BlobWriter("application/octet-stream"), { let blob = await zipGetData( entry, new BlobWriter("application/octet-stream"), { onprogress: (bytes, len) => { onProgress("unpack", partition, bytes / len); }, }); } ); common.logDebug(`Flashing ${partition}`); onProgress("flash", partition, 0.0); Loading Loading @@ -172,18 +189,22 @@ export async function flashZip( 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 entry.getData(new BlobWriter("application/zip"), { let imagesBlob = await zipGetData( entry, new BlobWriter("application/zip"), { onprogress: (bytes, len) => { onProgress("unpack", "images", bytes / len); }, }); } ); let imageReader = new ZipReader(new BlobReader(imagesBlob)); let imageEntries = await imageReader.getEntries(); // 3. Check requirements entry = imageEntries.find((e) => e.filename === "android-info.txt"); if (entry !== undefined) { let reqText = await entry.getData(new TextWriter()); let reqText = await zipGetData(entry, new TextWriter()); await checkRequirements(device, reqText); } Loading Loading @@ -214,7 +235,8 @@ export async function flashZip( let superAction = wipe ? "wipe" : "flash"; onProgress(superAction, "super", 0.0); let superBlob = await entry.getData( let superBlob = await zipGetData( entry, new BlobWriter("application/octet-stream") ); await device.upload( Loading Loading
lib/factory.js +34 −12 Original line number Diff line number Diff line Loading @@ -34,14 +34,31 @@ const BOOTLOADER_REBOOT_TIME = 4000; // ms const FASTBOOTD_REBOOT_TIME = 16000; // ms const USERDATA_ERASE_TIME = 1000; // ms // Wrapper for Entry#getData() to unwrap ProgressEvent errors async function zipGetData(entry, writer, options = undefined) { try { return await entry.getData(writer, options); } catch (e) { if (e instanceof ProgressEvent && e.type === "error") { throw e.target.error; } else { throw e; } } } async function flashEntryBlob(device, entry, onProgress, partition) { common.logDebug(`Unpacking ${partition}`); onProgress("unpack", partition, 0.0); let blob = await entry.getData(new BlobWriter("application/octet-stream"), { let blob = await zipGetData( entry, new BlobWriter("application/octet-stream"), { onprogress: (bytes, len) => { onProgress("unpack", partition, bytes / len); }, }); } ); common.logDebug(`Flashing ${partition}`); onProgress("flash", partition, 0.0); Loading Loading @@ -172,18 +189,22 @@ export async function flashZip( 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 entry.getData(new BlobWriter("application/zip"), { let imagesBlob = await zipGetData( entry, new BlobWriter("application/zip"), { onprogress: (bytes, len) => { onProgress("unpack", "images", bytes / len); }, }); } ); let imageReader = new ZipReader(new BlobReader(imagesBlob)); let imageEntries = await imageReader.getEntries(); // 3. Check requirements entry = imageEntries.find((e) => e.filename === "android-info.txt"); if (entry !== undefined) { let reqText = await entry.getData(new TextWriter()); let reqText = await zipGetData(entry, new TextWriter()); await checkRequirements(device, reqText); } Loading Loading @@ -214,7 +235,8 @@ export async function flashZip( let superAction = wipe ? "wipe" : "flash"; onProgress(superAction, "super", 0.0); let superBlob = await entry.getData( let superBlob = await zipGetData( entry, new BlobWriter("application/octet-stream") ); await device.upload( Loading