Downloading and saving a zip file is giving out of memory error
Hi,
I am downloading a 408.9 MB zip file through URLStream class. Below is my code.
protected function window1_creationCompleteHandler(event:FlexEvent):void
{
var urlStream:URLStream = new URLStream();
var urlReq:URLRequest = new URLRequest(downloadUrl);
urlStream.addEventListener(ProgressEvent.PROGRESS, handleProgress);
urlStream.addEventListener(Event.COMPLETE, handleDownloadComplete);
urlStream.addEventListener(IOErrorEvent.IO_ERROR, handleIOError);
urlStream.load(urlReq);
}
private function handleProgress(event:ProgressEvent):void
{
progressBar.setProgress(event.bytesLoaded, event.bytesTotal);
progressBar.label = "Downloading [" + Math.round(event.bytesLoaded / event.bytesTotal * 100).toString() + "%]";
}
private var totalFile:uint;
private var currFile:uint;
private var fileList:Array;
private var albummStorageFile:File;
private var albumZipFile:File;
private function handleDownloadComplete(event:Event):void
{
var stream:URLStream = event.currentTarget as URLStream;
var data:ByteArray = new ByteArray();
stream.readBytes(data,0,stream.bytesAvailable);
albumZipFile = File.applicationStorageDirectory.resolvePath("seldex_album.zip");
var fileStream:FileStream = new FileStream();
fileStream.open(albumZipFile, FileMode.WRITE);
fileStream.writeBytes(data,0,data.length);
fileStream.close();
}
This line is giving error: Error #1000: The system is out of memory.
stream.readBytes(data,0,stream.bytesAvailable);
stream.bytesAvailable valus is 408975369 at runtime.
I don't know what's causing the error.
Please help.
Thanks in advance.
