Skip to main content
Known Participant
March 7, 2013
Answered

bytearray uncompress filestream wirtebytes error

  • March 7, 2013
  • 2 replies
  • 2380 views

Hi,

I'm developing an app for iPad in which I'm trying to load a zip file from a remote url, save that zip file on device and then trying to unzip it.

It works fine both on laptop(while testing as AIR app) and also on the device(iPad) if zip file size is around 20 - 25MB, with it's internal file being around 140 - 170MB. But if the zip file size is larger (beyond 50MB) then it crashes while uncompressing the zip file on the device. It still works fine on laptop though.

I'm compiling the code with Flex 4.6 overlayed on AIR 3.6

iPad iOS version is 6.0.1

Using following code :

private function unzipFile():void

        {

            progress = progress + fileName +' unzipFile started\n';

            saveLog();

            var zStream:FileStream = new FileStream();

            var bytes:ByteArray = new ByteArray();

            var fileName:String = new String();

            var flNameLength:uint;

            var xfldLength:uint;

            var offset:uint;

            var compSize:uint;

            var uncompSize:uint;

            var compMethod:int;

            var signature:int;

           

            progress = progress + fileName +'before zStream.open\n';

            saveLog();

            zStream.open(fileLocal, FileMode.READ);

           

            progress = progress + fileName +'after zStream.open\n';

            saveLog();

           

            bytes.endian = Endian.LITTLE_ENDIAN; 

            while (zStream.position < fileLocal.size)

            {  progress = progress + fileName +'before zStream.readBytesbytes, 0, 30\n';

                saveLog();

                zStream.readBytes(bytes, 0, 30);

               

                progress = progress + fileName +'after zStream.readBytesbytes, 0, 30\n';

                saveLog();

                bytes.position = 0;

                signature = bytes.readInt();

                if (signature != 0x04034b50)

                {

                    break;

                }

                bytes.position = 8;

                compMethod = bytes.readByte();

                offset = 0;

                bytes.position = 26;

                flNameLength = bytes.readShort();   

                offset += flNameLength;    

                bytes.position = 28;    

                xfldLength = bytes.readShort();

                offset += xfldLength;   

                zStream.readBytes(bytes, 30, offset);

                bytes.position = 30;

                fileName = bytes.readUTFBytes(flNameLength); 

                bytes.position = 18;

                compSize = bytes.readUnsignedInt(); 

                bytes.position = 22;  

                uncompSize = bytes.readUnsignedInt();

               

                progress = progress + fileName +'before zStream.readBytes(bytes, 0, compSize)\n';

                saveLog();

               

                zStream.readBytes(bytes, 0, compSize);

               

                progress = progress + fileName +'after zStream.readBytes(bytes, 0, compSize)\n';

                saveLog();

                if (compMethod == 😎

                {

                    try

                    {

                        progress = progress + fileName +' before bytes.uncompress\n';

                        saveLog();

                        bytes.uncompress(CompressionAlgorithm.DEFLATE);

                      

                        //bytes.uncompress(CompressionAlgorithm.LZMA);

                       

                        progress = progress + fileName +' after bytes.uncompress\n';

                        saveLog();

                       

                        //outFile(fileName, bytes); 

                    }

                    catch(error:Error)

                    {

                        progress = progress + fileName +' bytes.uncompress catch\n';

                        saveLog();

                    }

                }

              //write bytes to a file locally here

            }

        }

It fails on this line:

bytes.uncompress(CompressionAlgorithm.DEFLATE);

and gets inside catch block.

To avoid this problem, I also tried to load the file which was there in the zip file, directly using remote url(file size and download time will be more), but in this case, after loading the file, reading the bytearray data of it, when I try to write this bytearray to a filestream, it crashes again!

Just wanted to know if there is any file size limit on mobile\iOS devices, while unzipping a file and while writing bytearray data to a filesystem or am I doing something wrong here?

Kindly help, as I'm stuck with this and cannot really proceed on this project using Flex AIR if this doesn't work.

-Deepak

This topic has been closed for replies.
Correct answer iBr3nt

Hi Deepak,

I have a mobile AIR app that downloads zip files and unzips them on the device and I found that the device will run out of memory when processing zip files larger than 100 meg. Basically if you have a lot of content to download, instead of one large zip file, you'll need to break it up into smaller zip files and download one at a time.

I used URLStream to download the zip files and then used a 3rd party AS3 zip utility: http://code.google.com/p/airxzip/ to unzip the files and it seemed to work well for what I needed.

iBrent

2 replies

iBr3nt
iBr3ntCorrect answer
Inspiring
March 7, 2013

Hi Deepak,

I have a mobile AIR app that downloads zip files and unzips them on the device and I found that the device will run out of memory when processing zip files larger than 100 meg. Basically if you have a lot of content to download, instead of one large zip file, you'll need to break it up into smaller zip files and download one at a time.

I used URLStream to download the zip files and then used a 3rd party AS3 zip utility: http://code.google.com/p/airxzip/ to unzip the files and it seemed to work well for what I needed.

iBrent

Known Participant
March 8, 2013

Hi Brent,

Yes, for unzipping, we really have to split the zip files, as uncompress doesn't work for larger zip files(it crashes on device).

Since my file size would range from 200-400MB, for now, I'm planning to load the raw file directly(running out of time to deliver it :| ). This too was failing, when i tried to readByes\writeBytes, after loading the file completely(since it runs out of memory). But I came across a solution right here:

http://stackoverflow.com/questions/14583247/air-as3-download-large-file-trough-ipad-application

It basically writes data to the disk, as and when data gets downloaded in chunks. I felt it was a great idea! Apparantly, there won't be any memory issues too with that approach

And yes, as you have mentioned future plan would be to load and unzip zip files.

Thanks Brent, that helped too