English 中文(简体)
unzip a file in flex?
原标题:

help me some one can we unzip a file flex and we can maintain same directory structure.

问题回答

I have used FZip which works great. Internally it uses a ByteArray which has compression capabilities. You could probally use the same technique by reading the file into a ByteArray.

i got the sollution, if any one wants to unzip a file just go through this code written in action script.

package com.utils { import flash.filesystem.File; import flash.filesystem.FileMode; import flash.filesystem.FileStream; import flash.utils.ByteArray; import flash.utils.CompressionAlgorithm; import flash.utils.Endian;

public class ZIPDecoder
{
    private var source:String;
    private var fileName:String;
    private var targetpath:String;
    private var bytes:ByteArray=new ByteArray();
    public function ZIPDecoder()
    {
    this.source=source;
    this.targetpath=targetpath;
    }
     public function unzipFile(sourceFile,targetPath):void{
    var flNameLength;
    var xfldLength;
    var offset;
    var compSize;
    var uncompSize;
    var compMethod;
    var signature;  
    var zfile:File = File.applicationStorageDirectory.resolvePath(sourceFile);
    var zStream:FileStream = new FileStream();
    zStream.open(zfile, FileMode.READ);
    bytes.endian =  Endian.LITTLE_ENDIAN;
    while (zStream.position < zfile.size){
    // read fixed metadata portion of local file header
    zStream.readBytes(bytes, 0, 30);
    bytes.position = 0;
    signature = bytes.readInt();
    // if no longer reading data files, quit
    if (signature != 0x04034b50)
    {
        break;
    }
    bytes.position = 8;
    compMethod = bytes.readByte();  // store compression method (8 == Deflate)
     offset = 0;    // stores length of variable portion of metadata
    bytes.position = 26;  // offset to file name length
    flNameLength = bytes.readShort();    // store file name
    offset += flNameLength;     // add length of file name
    bytes.position = 28;    // offset to extra field length
    xfldLength = bytes.readShort();
    offset += xfldLength;    // add length of extra field
    // read variable length bytes between fixed-length header and compressed file data
    zStream.readBytes(bytes, 30, offset);
    bytes.position = 30;
    fileName = bytes.readUTFBytes(flNameLength); // read file name
    if (fileName.substr(fileName.length - 1, 1) !=  / )
   {
        bytes.position = 18;
        compSize = bytes.readUnsignedInt(); // store size of compressed portion
        bytes.position = 22; // offset to uncompressed size
        uncompSize = bytes.readUnsignedInt(); // store uncompressed size

        // read compressed file to offset 0 of bytes; for uncompressed files
        // the compressed and uncompressed size is the same
        zStream.readBytes(bytes, 0, compSize);

        if (compMethod == 8 ) // if file is compressed, uncompress
        {
            bytes.uncompress(CompressionAlgorithm.DEFLATE);

        }
        writeFile(targetPath, fileName, bytes); // call outFile() to write out the file
    }

    }
    }
    public function writeFile(baseDir,fileName,data){
    var outFile:File=File.applicationStorageDirectory;
    outFile=outFile.resolvePath(baseDir+File.separator+fileName);
    var outStream:FileStream=new FileStream();
    outStream.open(outFile,FileMode.WRITE);
    outStream.writeBytes(data, 0, data.length);
    outStream.close();

    } 
    }
}




相关问题
Disable button tooltip in AS3

I want to disable the tooltip on certain buttons. The tooltip manager seems to be an all or nothing solution. Is it possible to disable the tooltip for just one or two buttons?

Multiple Remote call made simultenously

I was making multiple remote calls and they are done sequentially and when I am getting a result event back it s triggering calls to all the methods with ResultEvent as an argument . I am supposed to ...

Attaching a property to an event in Flex/AS3

I have a parameter that needs to be passed along with an event. After unsuccessful attempts to place it on the type by extending the class, I ve been advised in another SO question to write a custom ...

Clearing RSL in Cache

I have built a flex application which has a "main" project and it is assosciated with a few RSL s which are loaded and cached once i run my "main" application. The problem i am facing is that the ...

What s a good way of deserializing data into mock objects?

I m writing a mock backend service for my flex application. Because I will likely need to add/edit/modify the mock data over time, I d prefer not to generate the data in code like this: var mockData =...

AS3 try/catch out of memory

I m loading a few huge images on my flex/as3 app, but I can t manage to catch the error when the flash player runs out of memory. Here is the what I was thinking might work (I use ???? because i dont ...

热门标签