Search code examples
actionscript-3flashairziploader

AS3: How to check, all zip files has been extracted?


How to check all zip files has been extracted?

var reader: ZipFileReader = new ZipFileReader();
    reader.addEventListener(ZipEvent.ZIP_DATA_UNCOMPRESS, zipDataUncompressHandler);
    var zipFile: File = new File(zipFilePath);
    reader.open(zipFile);



    var list: Array = reader.getEntries();
    zipFileCount = list.length;
    trace(zipFileCount + " Numbers of items");

    for each(var entry: ZipEntry in list) {
        var filename: String = entry.getFilename();

        if (entry.isDirectory()) {
            trace("DIR  --->" + filename);
        } else {
            trace("FILE --->" + filename + "(" + entry.getCompressRate() + ")");
            reader.unzipAsync(entry);
        }
        zipFileWritedCount = zipFileWritedCount + 1;
    }
    function zipDataUncompressHandler(e: ZipEvent): void {

        var entry: ZipEntry = e.entry;

        var zfile: File = File.userDirectory.resolvePath('somefolder' + File.separator + entry.getFilename());
        var fs: FileStream = new FileStream();
        fs.open(zfile, FileMode.WRITE);
        fs.writeBytes(e.data);

        fs.close();

        trace("Refresh Scene");
        //include "RefreshScene.as";

    }

My files were extracted, but I need to check all files are actually extracted. Is there any way i can do that.

And I am using airxzip while working with zip file.

Also if I can add an loader.


Solution

    • You can shorten zipFileWritedCount = zipFileWritedCount + 1;

      By using just a zipFileWritedCount +=1; or even zipFileWritedCount++;

    • Anyways for checking the "all files extracted" amount you could try the Equality == operator as mentioned in the manual.

    Quick example :

    for each(var entry: ZipEntry in list) 
    {
        var filename: String = entry.getFilename();
    
        if ( entry.isDirectory() ) { trace("DIR  --->" + filename); } 
        else 
        {
            trace("FILE --->" + filename + "(" + entry.getCompressRate() + ")");
            reader.unzipAsync(entry);
        }
        zipFileWritedCount += 1; //add plus 1
    
        if ( zipFileWritedCount == zipFileCount ) //if Equal to zipFileCount..
        {
            trace ("unzipped all files..."); 
            trace ("zipFileCount: " + zipFileCount + " -VS- " + "zipFileWritedCount: " + zipFileWritedCount )
        }
    
    }