@@ -505,21 +505,20 @@ class ObfProcessor extends BaseProcessor {
505505 return tree ;
506506 }
507507
508- let adapter = {
509- listFiles : async ( ) : Promise < string [ ] > => {
510- return await listDir ( filePathOrBuffer as string ) ;
511- } ,
508+ this . zipFile = {
512509 readFile : async ( name : string ) : Promise < Uint8Array > => {
513510 return await readBinaryFromInput ( join ( filePathOrBuffer as string , name ) ) ;
514511 } ,
512+ listFiles : ( ) => {
513+ throw new Error ( 'Not implemented for directory input' ) ;
514+ } ,
515+ writeFiles : ( ) => {
516+ throw new Error ( 'Not implemented for directory input' ) ;
517+ } ,
515518 } ;
516519 if ( fileType === 'zip' ) {
517520 try {
518- const zipAdapter = await this . options . zipAdapter ( filePathOrBuffer ) ;
519- adapter = {
520- ...zipAdapter ,
521- listFiles : async ( ) => Promise . resolve ( zipAdapter . listFiles ( ) ) ,
522- } ;
521+ this . zipFile = await this . options . zipAdapter ( filePathOrBuffer ) ;
523522 } catch ( err ) {
524523 console . error ( '[OBF] Error loading ZIP:' , err ) ;
525524 throw err ;
@@ -532,14 +531,15 @@ class ObfProcessor extends BaseProcessor {
532531 console . log ( '[OBF] Detected zip archive, extracting .obf files' ) ;
533532
534533 // List manifest and OBF files
535- const filesInZip = await adapter . listFiles ( ) ;
534+ const filesInZip =
535+ fileType === 'zip' ? this . zipFile . listFiles ( ) : await listDir ( filePathOrBuffer as string ) ;
536536 const manifestFile = filesInZip . filter ( ( name ) => name . toLowerCase ( ) === 'manifest.json' ) ;
537537 let obfEntries = filesInZip . filter ( ( name ) => name . toLowerCase ( ) . endsWith ( '.obf' ) ) ;
538538
539539 // Attempt to read manifest
540540 if ( manifestFile && manifestFile . length === 1 ) {
541541 try {
542- const content = await adapter . readFile ( manifestFile [ 0 ] ) ;
542+ const content = await this . zipFile . readFile ( manifestFile [ 0 ] ) ;
543543 const data = decodeText ( content ) ;
544544 const str = typeof data === 'string' ? data : await readTextFromInput ( data ) ;
545545 if ( ! str . trim ( ) ) throw new Error ( 'Manifest object missing' ) ;
@@ -564,7 +564,7 @@ class ObfProcessor extends BaseProcessor {
564564 // Process each .obf entry
565565 for ( const entryName of obfEntries ) {
566566 try {
567- const content = await adapter . readFile ( entryName ) ;
567+ const content = await this . zipFile . readFile ( entryName ) ;
568568 const boardData = await tryParseObfJson ( decodeText ( content ) ) ;
569569 if ( boardData ) {
570570 const page = await this . processBoard ( boardData , entryName , true ) ;
@@ -790,7 +790,7 @@ class ObfProcessor extends BaseProcessor {
790790 await writeBinaryToPath ( outputPath , zipData ) ;
791791 } else {
792792 console . log ( '[OBF] Saving to directory:' , outputPath ) ;
793- if ( ! ( await pathExists ( outputPath ) ) ) await mkDir ( outputPath )
793+ if ( ! ( await pathExists ( outputPath ) ) ) await mkDir ( outputPath ) ;
794794 await Promise . all (
795795 files . map ( ( file ) => writeBinaryToPath ( join ( outputPath , file . name ) , file . data ) )
796796 ) ;
0 commit comments