<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Resumable File Downloader &#8211; Simple AIR app</title>
	<atom:link href="http://mariusht.com/blog/2010/03/10/resumable-file-downloader-simple-air-app/feed/" rel="self" type="application/rss+xml" />
	<link>http://mariusht.com/blog/2010/03/10/resumable-file-downloader-simple-air-app/</link>
	<description>A blog about Flex Development.</description>
	<lastBuildDate>Mon, 17 Oct 2011 22:40:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Mariush T.</title>
		<link>http://mariusht.com/blog/2010/03/10/resumable-file-downloader-simple-air-app/comment-page-1/#comment-368</link>
		<dc:creator>Mariush T.</dc:creator>
		<pubDate>Mon, 10 Oct 2011 12:34:00 +0000</pubDate>
		<guid isPermaLink="false">http://mariusht.com/blog/?p=1884#comment-368</guid>
		<description>Hi Joel,
This application wouldn&#039;t work with Flash Player running in the browser. &#039;For security reasons, a Macromedia Flash movie playing in a web browser is not allowed to access data that resides outside the exact web domain from which the SWF originated.&#039;
Best Regards</description>
		<content:encoded><![CDATA[<p>Hi Joel,<br />
This application wouldn&#8217;t work with Flash Player running in the browser. &#8216;For security reasons, a Macromedia Flash movie playing in a web browser is not allowed to access data that resides outside the exact web domain from which the SWF originated.&#8217;<br />
Best Regards</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joel Stobart</title>
		<link>http://mariusht.com/blog/2010/03/10/resumable-file-downloader-simple-air-app/comment-page-1/#comment-367</link>
		<dc:creator>Joel Stobart</dc:creator>
		<pubDate>Mon, 10 Oct 2011 07:41:11 +0000</pubDate>
		<guid isPermaLink="false">http://mariusht.com/blog/?p=1884#comment-367</guid>
		<description>Hi,
Probably a stupid question but, would this work with flash?
Joel</description>
		<content:encoded><![CDATA[<p>Hi,<br />
Probably a stupid question but, would this work with flash?<br />
Joel</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sunny</title>
		<link>http://mariusht.com/blog/2010/03/10/resumable-file-downloader-simple-air-app/comment-page-1/#comment-345</link>
		<dc:creator>sunny</dc:creator>
		<pubDate>Fri, 25 Feb 2011 09:00:02 +0000</pubDate>
		<guid isPermaLink="false">http://mariusht.com/blog/?p=1884#comment-345</guid>
		<description>import flash.events.Event;
			import flash.events.ProgressEvent;
			import flash.net.URLRequest;
			import flash.net.URLStream;
			import flash.utils.ByteArray;
			
			import mx.controls.Alert;
			import mx.events.FlexEvent;
			
			private var urlStream:URLStream;
			private var fData:ByteArray;
			
			private var bytesLoaded:Number = 0;
			private var totalBytesLoaded:Number = 0;
			private var bytesTotal:Number = 0;
			
			private var fileName:String = &#039;&#039;;
			private var file:File;
			
			private var fileStream:FileStream = new FileStream;
						
			protected function init(event:FlexEvent):void
			{
				urlStream = new URLStream;
				urlStream.addEventListener(ProgressEvent.PROGRESS, onProgress);
				urlStream.addEventListener(Event.COMPLETE, onComplete);
				fileInput.text = &quot;http://10.10.10.21/mov/cats.avi&quot;;
			}
			
			private function startDownload():void
			{
				bytesLoaded = 0;
				bytesTotal = 0;
				totalBytesLoaded = 0;
				
				var url:String = fileInput.text;
				var index:int = url.lastIndexOf(&#039;/&#039;);
				fileName = url.substring(index+1, url.length);
				file = File.desktopDirectory.resolvePath(fileName);
				status = file.url;
				
				if(file.exists)
				{
					btn.label = &#039;Download&#039;;
					mx.controls.Alert.show(&#039;Please remove &quot;&#039;+fileName+&#039;&quot; from your disk&#039;, &#039;File with the same name already exists&#039;);
					return;
				}
				output.text += &#039;Downloading...\n&#039;;
				
				urlStream.load( new URLRequest(url) );
				fData = new ByteArray;
				fileInput.enabled = false;
				
				fileStream.open(file, file.exists ? FileMode.APPEND:FileMode.WRITE);
			}
			
			private function pauseDownload():void
			{
				output.text += &#039;Downloading is paused\n&#039;;
				if(urlStream.connected)
				{					
					fData.clear();
					urlStream.readBytes(fData, fData.length);
					urlStream.close();					
					fileStream.writeBytes(fData);	
				}
				
				fileStream.close();
				
				totalBytesLoaded += bytesLoaded;
				trace( &quot;pause size:&quot;+ totalBytesLoaded);				
			
			}
			
			private function resumeDownload():void
			{
				output.text += &#039;Downloading... \n&#039;;
				output.text +=&#039;bytes=&#039;+totalBytesLoaded+&#039;-&#039;+bytesTotal + &#039;\n&#039;;
				var header0:URLRequestHeader = new URLRequestHeader(&#039;range&#039;, &#039;bytes=&#039;+totalBytesLoaded+&#039;-&#039;+bytesTotal);
				var request:URLRequest = new URLRequest(fileInput.text);
				request.requestHeaders.push(header0);
								
				urlStream.load( request );
				
				fileStream.open(file, file.exists ? FileMode.APPEND:FileMode.WRITE);				
				
			}
			
			private function onProgress(event:ProgressEvent):void
			{
				bytesLoaded = event.bytesLoaded;
				if(bytesTotal == 0)
					bytesTotal = event.bytesTotal;
				
				trace( &quot;size:&quot;+ bytesLoaded);
				
				progressBar.setProgress( (totalBytesLoaded + event.bytesLoaded) / bytesTotal, progressBar.maximum);
				
				if(urlStream.bytesAvailable == 0) return;
				if(urlStream.connected) 
				{
					fData.clear();
					urlStream.readBytes(fData, fData.length);
					fileStream.writeBytes(fData);
					
				}
			}
			
			private function onComplete(event:Event):void
			{
				output.text += &#039;Download complete\n&#039;;
				bytesLoaded = 0;
				bytesTotal = 0;
				totalBytesLoaded = 0;
				progressBar.setProgress(0, 1);
							
								
				if(urlStream.connected) 
				{
					fData.clear();
					urlStream.readBytes(fData, fData.length);
					urlStream.close();					
					fileStream.writeBytes(fData);					
				}
				
				
				fileInput.enabled = true;
				btn.label = &#039;Download&#039;;				
				fData = null;
								
				fileStream.close();
				
				System.gc();
			}
			
			private function writeFile():void
			{
				output.text += &#039;Saving File...\n&#039;;
				var fileStream:FileStream = new FileStream;
				fileStream.open(file, file.exists ? FileMode.APPEND:FileMode.WRITE);
				fileStream.writeBytes(fData);
				fileStream.close();
				output.text += &#039;File Saved\n&#039;;
			}
			
			private function btnClickHandler():void
			{
				if(bytesLoaded == 0)
				{
					btn.label = &#039;Pause&#039;;
					startDownload();
				}
				else
				{
					if(urlStream.connected)
					{
						btn.label = &#039;Resume&#039;;
						pauseDownload();
					}
					else
					{
						btn.label = &#039;Pause&#039;;
						resumeDownload();
					}
				}
			}</description>
		<content:encoded><![CDATA[<p>import flash.events.Event;<br />
			import flash.events.ProgressEvent;<br />
			import flash.net.URLRequest;<br />
			import flash.net.URLStream;<br />
			import flash.utils.ByteArray;</p>
<p>			import mx.controls.Alert;<br />
			import mx.events.FlexEvent;</p>
<p>			private var urlStream:URLStream;<br />
			private var fData:ByteArray;</p>
<p>			private var bytesLoaded:Number = 0;<br />
			private var totalBytesLoaded:Number = 0;<br />
			private var bytesTotal:Number = 0;</p>
<p>			private var fileName:String = &#8221;;<br />
			private var file:File;</p>
<p>			private var fileStream:FileStream = new FileStream;</p>
<p>			protected function init(event:FlexEvent):void<br />
			{<br />
				urlStream = new URLStream;<br />
				urlStream.addEventListener(ProgressEvent.PROGRESS, onProgress);<br />
				urlStream.addEventListener(Event.COMPLETE, onComplete);<br />
				fileInput.text = &#8220;http://10.10.10.21/mov/cats.avi&#8221;;<br />
			}</p>
<p>			private function startDownload():void<br />
			{<br />
				bytesLoaded = 0;<br />
				bytesTotal = 0;<br />
				totalBytesLoaded = 0;</p>
<p>				var url:String = fileInput.text;<br />
				var index:int = url.lastIndexOf(&#8217;/');<br />
				fileName = url.substring(index+1, url.length);<br />
				file = File.desktopDirectory.resolvePath(fileName);<br />
				status = file.url;</p>
<p>				if(file.exists)<br />
				{<br />
					btn.label = &#8216;Download&#8217;;<br />
					mx.controls.Alert.show(&#8217;Please remove &#8220;&#8216;+fileName+&#8217;&#8221; from your disk&#8217;, &#8216;File with the same name already exists&#8217;);<br />
					return;<br />
				}<br />
				output.text += &#8216;Downloading&#8230;\n&#8217;;</p>
<p>				urlStream.load( new URLRequest(url) );<br />
				fData = new ByteArray;<br />
				fileInput.enabled = false;</p>
<p>				fileStream.open(file, file.exists ? FileMode.APPEND:FileMode.WRITE);<br />
			}</p>
<p>			private function pauseDownload():void<br />
			{<br />
				output.text += &#8216;Downloading is paused\n&#8217;;<br />
				if(urlStream.connected)<br />
				{<br />
					fData.clear();<br />
					urlStream.readBytes(fData, fData.length);<br />
					urlStream.close();<br />
					fileStream.writeBytes(fData);<br />
				}</p>
<p>				fileStream.close();</p>
<p>				totalBytesLoaded += bytesLoaded;<br />
				trace( &#8220;pause size:&#8221;+ totalBytesLoaded);				</p>
<p>			}</p>
<p>			private function resumeDownload():void<br />
			{<br />
				output.text += &#8216;Downloading&#8230; \n&#8217;;<br />
				output.text +=&#8217;bytes=&#8217;+totalBytesLoaded+&#8217;-'+bytesTotal + &#8216;\n&#8217;;<br />
				var header0:URLRequestHeader = new URLRequestHeader(&#8217;range&#8217;, &#8216;bytes=&#8217;+totalBytesLoaded+&#8217;-'+bytesTotal);<br />
				var request:URLRequest = new URLRequest(fileInput.text);<br />
				request.requestHeaders.push(header0);</p>
<p>				urlStream.load( request );</p>
<p>				fileStream.open(file, file.exists ? FileMode.APPEND:FileMode.WRITE);				</p>
<p>			}</p>
<p>			private function onProgress(event:ProgressEvent):void<br />
			{<br />
				bytesLoaded = event.bytesLoaded;<br />
				if(bytesTotal == 0)<br />
					bytesTotal = event.bytesTotal;</p>
<p>				trace( &#8220;size:&#8221;+ bytesLoaded);</p>
<p>				progressBar.setProgress( (totalBytesLoaded + event.bytesLoaded) / bytesTotal, progressBar.maximum);</p>
<p>				if(urlStream.bytesAvailable == 0) return;<br />
				if(urlStream.connected)<br />
				{<br />
					fData.clear();<br />
					urlStream.readBytes(fData, fData.length);<br />
					fileStream.writeBytes(fData);</p>
<p>				}<br />
			}</p>
<p>			private function onComplete(event:Event):void<br />
			{<br />
				output.text += &#8216;Download complete\n&#8217;;<br />
				bytesLoaded = 0;<br />
				bytesTotal = 0;<br />
				totalBytesLoaded = 0;<br />
				progressBar.setProgress(0, 1);</p>
<p>				if(urlStream.connected)<br />
				{<br />
					fData.clear();<br />
					urlStream.readBytes(fData, fData.length);<br />
					urlStream.close();<br />
					fileStream.writeBytes(fData);<br />
				}</p>
<p>				fileInput.enabled = true;<br />
				btn.label = &#8216;Download&#8217;;<br />
				fData = null;</p>
<p>				fileStream.close();</p>
<p>				System.gc();<br />
			}</p>
<p>			private function writeFile():void<br />
			{<br />
				output.text += &#8216;Saving File&#8230;\n&#8217;;<br />
				var fileStream:FileStream = new FileStream;<br />
				fileStream.open(file, file.exists ? FileMode.APPEND:FileMode.WRITE);<br />
				fileStream.writeBytes(fData);<br />
				fileStream.close();<br />
				output.text += &#8216;File Saved\n&#8217;;<br />
			}</p>
<p>			private function btnClickHandler():void<br />
			{<br />
				if(bytesLoaded == 0)<br />
				{<br />
					btn.label = &#8216;Pause&#8217;;<br />
					startDownload();<br />
				}<br />
				else<br />
				{<br />
					if(urlStream.connected)<br />
					{<br />
						btn.label = &#8216;Resume&#8217;;<br />
						pauseDownload();<br />
					}<br />
					else<br />
					{<br />
						btn.label = &#8216;Pause&#8217;;<br />
						resumeDownload();<br />
					}<br />
				}<br />
			}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sunny</title>
		<link>http://mariusht.com/blog/2010/03/10/resumable-file-downloader-simple-air-app/comment-page-1/#comment-344</link>
		<dc:creator>sunny</dc:creator>
		<pubDate>Fri, 25 Feb 2011 08:58:53 +0000</pubDate>
		<guid isPermaLink="false">http://mariusht.com/blog/?p=1884#comment-344</guid>
		<description>When downloading large files will consume a lot of memory.
I have fixed the problem.

---------------------------------------------------------------------------



	
		
	
	
	
	
	
	
	
	
</description>
		<content:encoded><![CDATA[<p>When downloading large files will consume a lot of memory.<br />
I have fixed the problem.</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mariush T.</title>
		<link>http://mariusht.com/blog/2010/03/10/resumable-file-downloader-simple-air-app/comment-page-1/#comment-338</link>
		<dc:creator>Mariush T.</dc:creator>
		<pubDate>Sat, 13 Nov 2010 13:25:52 +0000</pubDate>
		<guid isPermaLink="false">http://mariusht.com/blog/?p=1884#comment-338</guid>
		<description>Thank you Aaron for fixing it and sharing the code.</description>
		<content:encoded><![CDATA[<p>Thank you Aaron for fixing it and sharing the code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron Hardy</title>
		<link>http://mariusht.com/blog/2010/03/10/resumable-file-downloader-simple-air-app/comment-page-1/#comment-337</link>
		<dc:creator>Aaron Hardy</dc:creator>
		<pubDate>Fri, 12 Nov 2010 03:49:52 +0000</pubDate>
		<guid isPermaLink="false">http://mariusht.com/blog/?p=1884#comment-337</guid>
		<description>Hey, thanks for the sample app. It&#039;s got a bug though.  You&#039;ll notice if you pause/resume a few times the resulting file will not be as large as the original.  The fix is to replace this:

if(bytesTotal != event.bytesTotal)
					bytesTotal = event.bytesTotal;
				
				progressBar.setProgress( (totalBytesLoaded + event.bytesLoaded) / event.bytesTotal, progressBar.maximum);

--------------

with this:

--------------
if(bytesTotal == 0)
					bytesTotal = event.bytesTotal;
				
				progressBar.setProgress( (totalBytesLoaded + event.bytesLoaded) / bytesTotal, progressBar.maximum);</description>
		<content:encoded><![CDATA[<p>Hey, thanks for the sample app. It&#8217;s got a bug though.  You&#8217;ll notice if you pause/resume a few times the resulting file will not be as large as the original.  The fix is to replace this:</p>
<p>if(bytesTotal != event.bytesTotal)<br />
					bytesTotal = event.bytesTotal;</p>
<p>				progressBar.setProgress( (totalBytesLoaded + event.bytesLoaded) / event.bytesTotal, progressBar.maximum);</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>with this:</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8211;<br />
if(bytesTotal == 0)<br />
					bytesTotal = event.bytesTotal;</p>
<p>				progressBar.setProgress( (totalBytesLoaded + event.bytesLoaded) / bytesTotal, progressBar.maximum);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vkwave</title>
		<link>http://mariusht.com/blog/2010/03/10/resumable-file-downloader-simple-air-app/comment-page-1/#comment-304</link>
		<dc:creator>vkwave</dc:creator>
		<pubDate>Tue, 13 Apr 2010 09:48:30 +0000</pubDate>
		<guid isPermaLink="false">http://mariusht.com/blog/?p=1884#comment-304</guid>
		<description>Dear Mariusz,
Thank you very much for sharing your experience code. I was working on the same and also got help from  http://richapps.de/?p=113.

Thank you again to share your code.</description>
		<content:encoded><![CDATA[<p>Dear Mariusz,<br />
Thank you very much for sharing your experience code. I was working on the same and also got help from  <a href="http://richapps.de/?p=113" rel="nofollow">http://richapps.de/?p=113</a>.</p>
<p>Thank you again to share your code.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

