768x90 Getting Online Shouldn't be Tough- $7.49 .com Domains at Go Daddy

List and read files and directories in a zip file

First of all you should download library here

And then short play with script below
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">


<mx:Script>
<![CDATA[
import mx.controls.Alert;
import nochump.util.zip.ZipEntry;
import mx.events.ListEvent;
import nochump.util.zip.ZipFile;
[Bindable]private var _zipFile:ZipFile;
[Bindable]private var _file:File;

private function browseFile():void{
var _file:File = new File();
_file.browseForOpen("Open.", getTypes());
_file.addEventListener(Event.SELECT, fileSelected);
}

private function getTypes():Array {
var allTypes:Array = new Array(getImageTypeFilter());
return allTypes;
}

private function getImageTypeFilter():FileFilter {
return new FileFilter("ZIP File", "*.zip");
}

private function setFileInfo(name:String, size:uint):void {
zipFileLabel.text = "Archive: " + name + " (" + sizeFormatter.format(size) + " bytes)";
}

private function fileSelected(event:Event):void {
_file = event.currentTarget as File;
var urlStream:URLStream = new URLStream();
urlStream.addEventListener(Event.COMPLETE, completeHandler);
urlStream.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
urlStream.addEventListener(SecurityErrorEvent.SECURITY_ERROR, errorHandler);
urlStream.load(new URLRequest(_file.nativePath));
}

private function completeHandler(event:Event):void {
var data:URLStream = URLStream(event.target);
setFileInfo(_file.name, data.bytesAvailable);
_zipFile = new ZipFile(data);
}

private function errorHandler(event:ErrorEvent):void {
Alert.show(event.text);
}

private function itemClickEvent(event:ListEvent):void {
var entry:ZipEntry = event.currentTarget.selectedItem as ZipEntry;
if(entry) taEntryData.text = String(_zipFile.getInput(entry));
}

private function labelSize(item:Object, column:DataGridColumn):String {
return sizeFormatter.format(item[column.dataField]);
}

private function labelModified(item:Object, column:DataGridColumn):String {
return dateFormatter.format(new Date(item.time));
}

private function labelCrc(item:Object, column:DataGridColumn):String {
return item.crc.toString(16).toUpperCase();
}

]]>
</mx:Script>

<mx:NumberFormatter id="sizeFormatter" useThousandsSeparator="true" />
<mx:DateFormatter id="dateFormatter" formatString="MM/DD/YYYY L:NN A" />

<mx:Panel title="Zip Demo" height="100%" width="100%">
<mx:Label id="zipFileLabel" />
<mx:VDividedBox width="100%" height="100%">
<mx:DataGrid id="dgEntries" width="100%" height="100%" dataProvider="{_zipFile.entries}" itemClick="itemClickEvent(event);">
<mx:columns>
<mx:DataGridColumn headerText="Name" dataField="name" width="300" />
<mx:DataGridColumn headerText="Size" dataField="size" labelFunction="labelSize" />
<mx:DataGridColumn headerText="Packed" dataField="compressedSize" labelFunction="labelSize" />
<mx:DataGridColumn headerText="Modified" labelFunction="labelModified" width="150" />
<mx:DataGridColumn headerText="CRC32" labelFunction="labelCrc" />
</mx:columns>
</mx:DataGrid>
<mx:TextArea id="taEntryData" width="100%" height="100%">
</mx:TextArea>
</mx:VDividedBox>
<mx:ControlBar>
<mx:Spacer width="100%"/>
<mx:HBox>
<mx:Form>
<mx:FormItem label="Open Zip File:" width="100%" styleName="lblForm" required="true">
<mx:Button id="btnBrowse" label="Browse" click="{browseFile()}"/>
</mx:FormItem>
</mx:Form>
</mx:HBox>
</mx:ControlBar>
</mx:Panel>



</mx:WindowedApplication>

No Response to "List and read files and directories in a zip file"

 
powered by Blogger