ZipFileReader class can NOT make directory or file.
So you should make directory or file according to ZipEntry.isDirectory() method.

var file:File = File.desktopDirectory.resolvePath("sample.zip");
			
var reader:ZipFileReader = new ZipFileReader();
reader.open(file);
var fileList:Array = reader.getEntries();
var baseDir:File = File.documentsDirectory();

for each(var entry:ZipEntry in fileList){
	var filename:String = entry.getFilename();
	
	if(entry.isDirectory()){
		//  If entry is directory 
		var dir:File = baseDir.resolvePath(filename);
		dir.createDirectory();
	}
	else{
		var unzippedBytes:ByteArray = reader.unzip(entry);
		var file:File = baseDir.resolvePath(filename);
		var fs:FileStream = new FileStream(FileMode.WRITE);
		fs.writeBytes(unzippedBytes,0,unzippedBytes.length);
		fs.close();
	}
}
reader.close();

Related Posts

10 Responses to “airxzip:Unzip Directory or File”

  • Jackie より:

    thank you very much for your code sample. It works great to unzip 300MB zip file on Windows !!! But I tried to use it on iPad, it crash when unzip a 300MB file. Could you please improve the code a little bit to support ipad? That would be wonderful. Thanks in advance!

  • coltware より:

    Hi jackie
    Thank you for using my library.

    >But I tried to use it on iPad, it crash when unzip a 300MB file.
    >Could you please improve the code a little bit to support ipad? That would be wonderful.

    It means you can unzip small file on ipad ?
    If you can, that must be memory size problem.

    To be precise,airxzip does NOT depends on zip file size.
    Airxzip depends on each entry file size.
    So If big zip file have a lot of small file, That OK.

    But If big zip file have ONE big entry file,
    that’s too big problem for airxzip.
    The Reason are …

    * airxzip depends on compress/uncompress as3 native function
    ex)
    var bytes:ByteArray = …..
    var raw:ByteArray = bytes.uncompress(CompressionAlgorithm.DEFLATE);

    (300M or more ) = (300M).uncompress means 600M bytes or more..

    But as3 can’t support streaming unzip or zip function.
    So if I make uncompress method that not depends on file size,
    I should make as3 native deflate or inflate function.
    But these function are too slow.

    So I’d like to support ANE, but I have a time to make it now,
    And I don’t have ipad( and iOS developer fee is too expensive for my hobbies ).

    So sorry…
    But I welcome somebody to join my airxzip project.
    If you are interesting in airxzip project,
    Please let me know !

  • song liu より:

    Thank you for providing such a nice library,But how do I remove a specified file from a zip file? I can’t find the way.

  • coltware より:

    Hi song

    >But how do I remove a specified file from a zip file? I can’t find the way.

    airxzip can’t edit zip file so far.
    So sorry…

  • song liu より:

    Thank you all the same.

  • Philipp M より:

    Hi great lib.
    But i had one Problem with the Filename Charset.
    My Zip has Files with öäü ÖÄÜ (i hope you can see it).
    I need to use charset something like ISO 8859-1 (latin-1).

    But When i try to set another Charset, nothing happend.
    I become chars like this:

    �/
    „/

    I hope you can Help me

  • Philipp M より:

    I fixed it!
    The getter of the Filename must look like:

    entry.getFilename(“IBM850”);

    This is the correct Code for Germany!

  • coltware より:

    Hi Philipp

    Thank you for giving me info !

  • Tony Wu より:

    when unzip a big file with only one entry, it crashed said system out of memory, any workaround?

  • Turanligil より:

    Hello, thanks for this library. like Jackie i have the same problem. the unzipping on my ipad works fine but only with small filesized zipentries. in my case i have videos inside the zip file and the app chrashes on unzipping them … the biggest file is about 18MB… Do you know any native library wich can handle this

Leave a Reply

Spam protection by WP Captcha-Free

RSS
Add to Google
2012年2月
« 1月   3月 »
 1234
567891011
12131415161718
19202122232425
26272829