@@ -139,11 +139,17 @@ export function translateOptions<T extends Record<string, unknown>>(
139139 return result as T ;
140140}
141141
142+ const ApkBundleFileName = / a s s e t s \/ i n d e x .a n d r o i d .b u n d l e / ;
143+ const ApkUpdateJsonName = / r e s \/ r a w \/ u p d a t e .j s o n / ;
144+
142145export async function getApkInfo ( fn : string ) {
143146 const appInfoParser = new AppInfoParser ( fn ) ;
144- const bundleFile = await appInfoParser . parser . getEntry (
145- / a s s e t s \/ i n d e x .a n d r o i d .b u n d l e / ,
146- ) ;
147+ // read both entries in a single scan over the archive
148+ const entries = await appInfoParser . parser . getEntries ( [
149+ ApkBundleFileName ,
150+ ApkUpdateJsonName ,
151+ ] ) ;
152+ const bundleFile = entries [ String ( ApkBundleFileName ) ] ;
147153 if ( ! bundleFile ) {
148154 throw new Error (
149155 t ( 'bundleNotFound' , {
@@ -152,9 +158,7 @@ export async function getApkInfo(fn: string) {
152158 } ) ,
153159 ) ;
154160 }
155- const updateJsonFile = await appInfoParser . parser . getEntry (
156- / r e s \/ r a w \/ u p d a t e .j s o n / ,
157- ) ;
161+ const updateJsonFile = entries [ String ( ApkUpdateJsonName ) ] ;
158162 let appCredential = { } ;
159163 if ( updateJsonFile ) {
160164 appCredential = JSON . parse ( updateJsonFile . toString ( ) ) . android ;
@@ -182,9 +186,13 @@ export async function getApkInfo(fn: string) {
182186
183187export async function getAppInfo ( fn : string ) {
184188 const appInfoParser = new AppInfoParser ( fn ) ;
185- const bundleFile = await appInfoParser . parser . getEntryFromHarmonyApp (
186- / r a w f i l e \/ b u n d l e .h a r m o n y .j s / ,
187- ) ;
189+ // single scan (and single nested .hap extraction) for all three entries
190+ const [ bundleFile , updateJsonFile , metaJsonFile ] =
191+ await appInfoParser . parser . getEntriesFromHarmonyApp ( [
192+ / r a w f i l e \/ b u n d l e .h a r m o n y .j s / ,
193+ / r a w f i l e \/ u p d a t e .j s o n / ,
194+ / r a w f i l e \/ m e t a .j s o n / ,
195+ ] ) ;
188196 if ( ! bundleFile ) {
189197 throw new Error (
190198 t ( 'bundleNotFound' , {
@@ -193,14 +201,10 @@ export async function getAppInfo(fn: string) {
193201 } ) ,
194202 ) ;
195203 }
196- const updateJsonFile =
197- await appInfoParser . parser . getEntryFromHarmonyApp ( / r a w f i l e \/ u p d a t e .j s o n / ) ;
198204 let appCredential = { } ;
199205 if ( updateJsonFile ) {
200206 appCredential = JSON . parse ( updateJsonFile . toString ( ) ) . harmony ;
201207 }
202- const metaJsonFile =
203- await appInfoParser . parser . getEntryFromHarmonyApp ( / r a w f i l e \/ m e t a .j s o n / ) ;
204208 let metaData : ParsedAppMetaInfo = { } ;
205209 if ( metaJsonFile ) {
206210 metaData = JSON . parse ( metaJsonFile . toString ( ) ) as ParsedAppMetaInfo ;
@@ -216,11 +220,23 @@ export async function getAppInfo(fn: string) {
216220 return { versionName, buildTime, ...appCredential } ;
217221}
218222
223+ const IpaBundleFileName = / p a y l o a d \/ .+ ?\. a p p \/ m a i n .j s b u n d l e / ;
224+ const IpaUpdateJsonName = / p a y l o a d \/ .+ ?\. a p p \/ a s s e t s \/ u p d a t e .j s o n / ;
225+ const IpaBuildTimeName = / p a y l o a d \/ .+ ?\. a p p \/ p u s h y _ b u i l d _ t i m e .t x t / ;
226+ // Not in root bundle when use `use_frameworks`
227+ const IpaBuildTimeFrameworkName =
228+ / p a y l o a d \/ .+ ?\. a p p \/ f r a m e w o r k s \/ r e a c t _ n a t i v e _ u p d a t e .f r a m e w o r k \/ p u s h y _ b u i l d _ t i m e .t x t / ;
229+
219230export async function getIpaInfo ( fn : string ) {
220231 const appInfoParser = new AppInfoParser ( fn ) ;
221- const bundleFile = await appInfoParser . parser . getEntry (
222- / p a y l o a d \/ .+ ?\. a p p \/ m a i n .j s b u n d l e / ,
223- ) ;
232+ // read all four entries in a single scan over the archive
233+ const entries = await appInfoParser . parser . getEntries ( [
234+ IpaBundleFileName ,
235+ IpaUpdateJsonName ,
236+ IpaBuildTimeName ,
237+ IpaBuildTimeFrameworkName ,
238+ ] ) ;
239+ const bundleFile = entries [ String ( IpaBundleFileName ) ] ;
224240 if ( ! bundleFile ) {
225241 throw new Error (
226242 t ( 'bundleNotFound' , {
@@ -229,24 +245,16 @@ export async function getIpaInfo(fn: string) {
229245 } ) ,
230246 ) ;
231247 }
232- const updateJsonFile = await appInfoParser . parser . getEntry (
233- / p a y l o a d \/ .+ ?\. a p p \/ a s s e t s \/ u p d a t e .j s o n / ,
234- ) ;
248+ const updateJsonFile = entries [ String ( IpaUpdateJsonName ) ] ;
235249 let appCredential = { } ;
236250 if ( updateJsonFile ) {
237251 appCredential = JSON . parse ( updateJsonFile . toString ( ) ) . ios ;
238252 }
239253 const { CFBundleShortVersionString : versionName } =
240254 await appInfoParser . parse < ParsedIpaInfo > ( ) ;
241- let buildTimeTxtBuffer = await appInfoParser . parser . getEntry (
242- / p a y l o a d \/ .+ ?\. a p p \/ p u s h y _ b u i l d _ t i m e .t x t / ,
243- ) ;
244- if ( ! buildTimeTxtBuffer ) {
245- // Not in root bundle when use `use_frameworks`
246- buildTimeTxtBuffer = await appInfoParser . parser . getEntry (
247- / p a y l o a d \/ .+ ?\. a p p \/ f r a m e w o r k s \/ r e a c t _ n a t i v e _ u p d a t e .f r a m e w o r k \/ p u s h y _ b u i l d _ t i m e .t x t / ,
248- ) ;
249- }
255+ const buildTimeTxtBuffer =
256+ entries [ String ( IpaBuildTimeName ) ] ??
257+ entries [ String ( IpaBuildTimeFrameworkName ) ] ;
250258 if ( ! buildTimeTxtBuffer ) {
251259 throw new Error ( t ( 'buildTimeNotFound' ) ) ;
252260 }
0 commit comments