@@ -460,9 +460,20 @@ class ObfProcessor extends BaseProcessor {
460460 }
461461 }
462462
463- // If input is a buffer or string that parses as OBF JSON
464- const asJson = tryParseObfJson ( filePathOrBuffer ) ;
465- if ( asJson ) {
463+ // Detect likely zip signature first
464+ function isLikelyZip ( input : ProcessorInput ) : boolean {
465+ if ( typeof input === 'string' ) {
466+ const lowered = input . toLowerCase ( ) ;
467+ return lowered . endsWith ( '.zip' ) || lowered . endsWith ( '.obz' ) ;
468+ }
469+ const bytes = readBinaryFromInput ( input ) ;
470+ return bytes . length >= 2 && bytes [ 0 ] === 0x50 && bytes [ 1 ] === 0x4b ;
471+ }
472+
473+ // Check if input is a buffer or string that parses as OBF JSON; throw if neither JSON nor ZIP
474+ if ( ! isLikelyZip ( filePathOrBuffer ) ) {
475+ const asJson = tryParseObfJson ( filePathOrBuffer ) ;
476+ if ( ! asJson ) throw new Error ( 'Invalid OBF content: not JSON and not ZIP' ) ;
466477 console . log ( '[OBF] Detected buffer/string as OBF JSON' ) ;
467478 const page = await this . processBoard ( asJson , '[bufferOrString]' ) ;
468479 tree . addPage ( page ) ;
@@ -482,20 +493,6 @@ class ObfProcessor extends BaseProcessor {
482493 return tree ;
483494 }
484495
485- // Otherwise, try as ZIP (.obz). Detect likely zip signature first; throw if neither JSON nor ZIP
486- function isLikelyZip ( input : ProcessorInput ) : boolean {
487- if ( typeof input === 'string' ) {
488- const lowered = input . toLowerCase ( ) ;
489- return lowered . endsWith ( '.zip' ) || lowered . endsWith ( '.obz' ) ;
490- }
491- const bytes = readBinaryFromInput ( input ) ;
492- return bytes . length >= 2 && bytes [ 0 ] === 0x50 && bytes [ 1 ] === 0x4b ;
493- }
494-
495- if ( ! isLikelyZip ( filePathOrBuffer ) ) {
496- throw new Error ( 'Invalid OBF content: not JSON and not ZIP' ) ;
497- }
498-
499496 try {
500497 const zipResult = this . options . zipAdapter
501498 ? await this . options . zipAdapter ( filePathOrBuffer )
0 commit comments