@@ -397,7 +397,7 @@ class ObfProcessor extends BaseProcessor {
397397 }
398398
399399 async loadIntoTree ( filePathOrBuffer : ProcessorInput ) : Promise < AACTree > {
400- const { readBinaryFromInput, readTextFromInput, listDir, join, isDirectory } =
400+ const { readBinaryFromInput, readTextFromInput, listDir, join, isDirectory, pathExists } =
401401 this . options . fileAdapter ;
402402 // Detailed logging for debugging input
403403 const bufferLength =
@@ -741,7 +741,7 @@ class ObfProcessor extends BaseProcessor {
741741 }
742742
743743 async saveFromTree ( tree : AACTree , outputPath : string ) : Promise < void > {
744- const { writeTextToPath, writeBinaryToPath, pathExists, isDirectory , join } =
744+ const { writeTextToPath, writeBinaryToPath, pathExists, mkDir , join } =
745745 this . options . fileAdapter ;
746746 if ( outputPath . endsWith ( '.obf' ) ) {
747747 // Save as single OBF JSON file
@@ -779,18 +779,21 @@ class ObfProcessor extends BaseProcessor {
779779 data : new TextEncoder ( ) . encode ( JSON . stringify ( manifest ) ) ,
780780 } ) ;
781781
782- if ( await isDirectory ( outputPath ) ) {
783- await Promise . all (
784- files . map ( ( file ) => writeBinaryToPath ( join ( outputPath , file . name ) , file . data ) )
785- ) ;
786- } else {
782+ if ( outputPath . endsWith ( '.obz' ) || outputPath . endsWith ( '.zip' ) ) {
783+ console . log ( '[OBF] Saving to ZIP file:' , outputPath ) ;
787784 const fileExists = await pathExists ( outputPath ) ;
788785 this . zipFile = await this . options . zipAdapter (
789786 fileExists ? outputPath : undefined ,
790787 this . options . fileAdapter
791788 ) ;
792789 const zipData = await this . zipFile . writeFiles ( files ) ;
793790 await writeBinaryToPath ( outputPath , zipData ) ;
791+ } else {
792+ console . log ( '[OBF] Saving to directory:' , outputPath ) ;
793+ if ( ! ( await pathExists ( outputPath ) ) ) await mkDir ( outputPath )
794+ await Promise . all (
795+ files . map ( ( file ) => writeBinaryToPath ( join ( outputPath , file . name ) , file . data ) )
796+ ) ;
794797 }
795798 }
796799 }
0 commit comments