package zip 
{
    import flash.events.Event;
    import flash.events.IOErrorEvent;
    import flash.filesystem.File;
    import flash.net.URLRequest;
	import flash.net.URLLoaderDataFormat;
    import flash.net.URLLoader;
    import flash.utils.ByteArray;
    import deng.fzip.FZip;
    import deng.fzip.FZipFile;
	import flash.filesystem.File;
    import flash.filesystem.FileMode;
    import flash.filesystem.FileStream;
	import Alert;
	

	public class ZIPResourceLoader 
	{
	
       public var resourcesURL:String = "https://redagereborn.ru/resources.zip";
       public var localFilePath:String = File.applicationStorageDirectory.nativePath + File.separator + "resources.zip";
       public var zipLoader:URLLoader = new URLLoader();


		public function ZIPResourceLoader() 
		{
            zipLoader.dataFormat = URLLoaderDataFormat.BINARY;
            zipLoader.addEventListener(Event.COMPLETE, onZipLoaded);
            zipLoader.addEventListener(IOErrorEvent.IO_ERROR, onZipLoadError);
		    zipLoader.addEventListener(Event.OPEN, onZipLoadStart); // показ окна, о начале
            zipLoader.load(new URLRequest(resourcesURL));
		}
		
		public function onZipLoadStart(event:Event):void 
        {
            Alert.showMessage("Load resources.zip started!");
        }
	
        public function onZipLoaded(event:Event):void 
	    {
            var zipBytes:ByteArray = zipLoader.data;
            var fileStream:FileStream = new FileStream();
            fileStream.open(new File(localFilePath), FileMode.WRITE);
            fileStream.writeBytes(zipBytes, 0, zipBytes.length);
            fileStream.close();
            var zipFile:FZip = new FZip();
            zipFile.addEventListener(Event.COMPLETE, this.onZipExtracted);
            zipFile.load(new URLRequest(localFilePath));
        }

        public function onZipLoadError(event:IOErrorEvent):void 
	    {
            Alert.showMessage("Failed to load resources.zip");
        }

        public function onZipExtracted(event:Event):void 
        {
            var zipFile:FZip = event.target as FZip;
            try {
                for (var i:int = 0; i < zipFile.getFileCount(); i++) 
                {
                    var zipEntry:FZipFile = zipFile.getFileAt(i);
                    var targetFilePath:String = File.applicationStorageDirectory.nativePath + File.separator + "cache/resources" + File.separator + zipEntry.filename;
                    var targetFile:File = new File(targetFilePath);
                    if (zipEntry.filename.charAt(zipEntry.filename.length - 1) == "/")
                    {
                        targetFile.createDirectory();
                    }
                    else 
                    {
                        var targetFileStream:FileStream = new FileStream();
                        targetFileStream.open(targetFile, FileMode.WRITE);
                        targetFileStream.writeBytes(zipEntry.content);
                        targetFileStream.close();
                    }
                }
                Alert.showMessage("Extracted successfully!");
            } catch (error:Error) {
            Alert.showMessage("Failed to extract resources.zip: " + error.message + " (" + error.errorID + ")");
            } 
        }
    }
} как сделать чтобы он сравнивал md5 суммы, тоесть он качал md5 в applicationStorageDirectory, сравнивал с тем который на хосте, если на хосте он различается то он качает архив по новой