<?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: Create zip files on the fly with ruby</title>
	<atom:link href="http://blog.devinterface.com/2010/02/create-zip-files-on-the-fly/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.devinterface.com/2010/02/create-zip-files-on-the-fly/</link>
	<description>Information Technology Professionals</description>
	<lastBuildDate>Fri, 03 Feb 2012 01:56:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Edward Rudd</title>
		<link>http://blog.devinterface.com/2010/02/create-zip-files-on-the-fly/comment-page-1/#comment-8861</link>
		<dc:creator>Edward Rudd</dc:creator>
		<pubDate>Tue, 20 Dec 2011 16:44:54 +0000</pubDate>
		<guid isPermaLink="false">http://blog.devinterface.com/?p=487#comment-8861</guid>
		<description>A few things to note.  Tempfile doesn&#039;t create file in memory (unless your tmp directory is in something like tmpfs).  Also you do not need to put Time.now or anything of the sort in the first parameter to the constructor.  Tempfile.new takes a &quot;basename&quot; which is the prefix used to create the temporary filename.. the underlying make_tmpname method already mixes in the time and a random value.</description>
		<content:encoded><![CDATA[<p>A few things to note.  Tempfile doesn&#8217;t create file in memory (unless your tmp directory is in something like tmpfs).  Also you do not need to put Time.now or anything of the sort in the first parameter to the constructor.  Tempfile.new takes a &#8220;basename&#8221; which is the prefix used to create the temporary filename.. the underlying make_tmpname method already mixes in the time and a random value.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rails: on-the-fly streaming of output in zip format?</title>
		<link>http://blog.devinterface.com/2010/02/create-zip-files-on-the-fly/comment-page-1/#comment-8852</link>
		<dc:creator>Rails: on-the-fly streaming of output in zip format?</dc:creator>
		<pubDate>Sun, 30 Oct 2011 02:27:22 +0000</pubDate>
		<guid isPermaLink="false">http://blog.devinterface.com/?p=487#comment-8852</guid>
		<description>[...] know that I can do streaming generation of zip files to the filesystemk using ZipOutputStream as here. I also know that I can do streaming output from a rails controller by setting response_body to a [...]</description>
		<content:encoded><![CDATA[<p>[...] know that I can do streaming generation of zip files to the filesystemk using ZipOutputStream as here. I also know that I can do streaming output from a rails controller by setting response_body to a [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Raphaël</title>
		<link>http://blog.devinterface.com/2010/02/create-zip-files-on-the-fly/comment-page-1/#comment-7549</link>
		<dc:creator>Raphaël</dc:creator>
		<pubDate>Wed, 20 Apr 2011 15:48:05 +0000</pubDate>
		<guid isPermaLink="false">http://blog.devinterface.com/?p=487#comment-7549</guid>
		<description>I&#039;ve been using your code for an application coded in Rails 2.0.2 (Ruby 1.8.6).

We had an issue that occurred very rarely: sometimes, during the send_file, the file was not found.

After much investigation, we understood why: the send_file has an option (:stream) which defaults to true. If set to true, the file is read and sent on the fly. The problem is that in your code, you close and delete the temporary file just after the send_file.
In our case, and maybe because we used an old version of Rails, the file was sometimes sent after being deleted (thus raising an error).

The solution is just to add :stream =&gt; false:
send_file t.path, :type =&gt; &#039;application/zip&#039;,
                             :disposition =&gt; &#039;attachment&#039;,
                             :filename =&gt; file_name,
                             :stream =&gt; false
t.close

With this option, the file is read BEFORE being sent, and then (and only then) closed. 

This option disappeared in Rails 3 (or around it) because it is handled in another way that I haven&#039;t investigated.
I&#039;d suggest you to add this for people who, like me, would come to your blog and experience the same problem :)</description>
		<content:encoded><![CDATA[<p>I&#8217;ve been using your code for an application coded in Rails 2.0.2 (Ruby 1.8.6).</p>
<p>We had an issue that occurred very rarely: sometimes, during the send_file, the file was not found.</p>
<p>After much investigation, we understood why: the send_file has an option (:stream) which defaults to true. If set to true, the file is read and sent on the fly. The problem is that in your code, you close and delete the temporary file just after the send_file.<br />
In our case, and maybe because we used an old version of Rails, the file was sometimes sent after being deleted (thus raising an error).</p>
<p>The solution is just to add :stream =&gt; false:<br />
send_file t.path, :type =&gt; &#8216;application/zip&#8217;,<br />
                             :disposition =&gt; &#8216;attachment&#8217;,<br />
                             :filename =&gt; file_name,<br />
                             :stream =&gt; false<br />
t.close</p>
<p>With this option, the file is read BEFORE being sent, and then (and only then) closed. </p>
<p>This option disappeared in Rails 3 (or around it) because it is handled in another way that I haven&#8217;t investigated.<br />
I&#8217;d suggest you to add this for people who, like me, would come to your blog and experience the same problem <img src='http://blog.devinterface.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Leda Stlaurent</title>
		<link>http://blog.devinterface.com/2010/02/create-zip-files-on-the-fly/comment-page-1/#comment-7432</link>
		<dc:creator>Leda Stlaurent</dc:creator>
		<pubDate>Tue, 05 Apr 2011 01:13:21 +0000</pubDate>
		<guid isPermaLink="false">http://blog.devinterface.com/?p=487#comment-7432</guid>
		<description>Very    fantastic  visual appeal on this  site, I&#039;d  value it 10 10.</description>
		<content:encoded><![CDATA[<p>Very    fantastic  visual appeal on this  site, I&#8217;d  value it 10 10.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: supernsetips</title>
		<link>http://blog.devinterface.com/2010/02/create-zip-files-on-the-fly/comment-page-1/#comment-7430</link>
		<dc:creator>supernsetips</dc:creator>
		<pubDate>Sun, 03 Apr 2011 10:55:14 +0000</pubDate>
		<guid isPermaLink="false">http://blog.devinterface.com/?p=487#comment-7430</guid>
		<description>Dude.. I am not much into reading, but somehow I got to read lots of articles on your website. Its amazing how interesting it is for me to visit you very often.</description>
		<content:encoded><![CDATA[<p>Dude.. I am not much into reading, but somehow I got to read lots of articles on your website. Its amazing how interesting it is for me to visit you very often.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Koen</title>
		<link>http://blog.devinterface.com/2010/02/create-zip-files-on-the-fly/comment-page-1/#comment-7168</link>
		<dc:creator>Koen</dc:creator>
		<pubDate>Thu, 17 Mar 2011 09:56:51 +0000</pubDate>
		<guid isPermaLink="false">http://blog.devinterface.com/?p=487#comment-7168</guid>
		<description>this didn&#039;t work for me on 1.8.7 in combination with heroku - i get an empty file - but when i closed the file and read it as data and streamed it as data with send_data than it does work.

 Zip::ZipOutputStream.open(file.path) do &#124;z&#124;
      files.each do &#124;wood, report&#124;
        title = wood.abbreviation+&quot;.txt&quot;
        z.put_next_entry(title)
        z.write report
      end
    end
    file.close
    file = File.open(file.path, &quot;r&quot;)
    data = file.read()
    send_data data, :type =&gt; &#039;application/zip&#039;, :disposition =&gt; &#039;attachment&#039;, :filename =&gt; file_name</description>
		<content:encoded><![CDATA[<p>this didn&#8217;t work for me on 1.8.7 in combination with heroku &#8211; i get an empty file &#8211; but when i closed the file and read it as data and streamed it as data with send_data than it does work.</p>
<p> Zip::ZipOutputStream.open(file.path) do |z|<br />
      files.each do |wood, report|<br />
        title = wood.abbreviation+&#8221;.txt&#8221;<br />
        z.put_next_entry(title)<br />
        z.write report<br />
      end<br />
    end<br />
    file.close<br />
    file = File.open(file.path, &#8220;r&#8221;)<br />
    data = file.read()<br />
    send_data data, :type =&gt; &#8216;application/zip&#8217;, :disposition =&gt; &#8216;attachment&#8217;, :filename =&gt; file_name</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Imelda Savary</title>
		<link>http://blog.devinterface.com/2010/02/create-zip-files-on-the-fly/comment-page-1/#comment-5488</link>
		<dc:creator>Imelda Savary</dc:creator>
		<pubDate>Sat, 05 Mar 2011 18:21:06 +0000</pubDate>
		<guid isPermaLink="false">http://blog.devinterface.com/?p=487#comment-5488</guid>
		<description>Tahnks for the interesting article!</description>
		<content:encoded><![CDATA[<p>Tahnks for the interesting article!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jose</title>
		<link>http://blog.devinterface.com/2010/02/create-zip-files-on-the-fly/comment-page-1/#comment-2968</link>
		<dc:creator>Jose</dc:creator>
		<pubDate>Mon, 07 Feb 2011 20:44:32 +0000</pubDate>
		<guid isPermaLink="false">http://blog.devinterface.com/?p=487#comment-2968</guid>
		<description>With Ruby 1.9.2 I found using z.write instead of z.print fixed my zip corruption problem.</description>
		<content:encoded><![CDATA[<p>With Ruby 1.9.2 I found using z.write instead of z.print fixed my zip corruption problem.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Simon</title>
		<link>http://blog.devinterface.com/2010/02/create-zip-files-on-the-fly/comment-page-1/#comment-2567</link>
		<dc:creator>Simon</dc:creator>
		<pubDate>Fri, 17 Dec 2010 13:13:21 +0000</pubDate>
		<guid isPermaLink="false">http://blog.devinterface.com/?p=487#comment-2567</guid>
		<description>Thanks for the article but I think it would be even better to call 

Time.now.to_i

this gives you the timestamp and will be an integer. The Time.now you use could contain all kind of strange characters (e.g. a slash or dots) which may pose some problems on certain file systems, don&#039;t you think?</description>
		<content:encoded><![CDATA[<p>Thanks for the article but I think it would be even better to call </p>
<p>Time.now.to_i</p>
<p>this gives you the timestamp and will be an integer. The Time.now you use could contain all kind of strange characters (e.g. a slash or dots) which may pose some problems on certain file systems, don&#8217;t you think?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hamlet</title>
		<link>http://blog.devinterface.com/2010/02/create-zip-files-on-the-fly/comment-page-1/#comment-1560</link>
		<dc:creator>Hamlet</dc:creator>
		<pubDate>Mon, 20 Sep 2010 12:20:19 +0000</pubDate>
		<guid isPermaLink="false">http://blog.devinterface.com/?p=487#comment-1560</guid>
		<description>Hi,
thanks for the tip about creating a zip file...
But where did you see that Tempfile was creating a file in memory ?

From the doc you linked :
&quot;Creates a temporary file of mode 0600 in the temporary directory&quot;

Otherwise it should fit your bill, 
Regards</description>
		<content:encoded><![CDATA[<p>Hi,<br />
thanks for the tip about creating a zip file&#8230;<br />
But where did you see that Tempfile was creating a file in memory ?</p>
<p>From the doc you linked :<br />
&#8220;Creates a temporary file of mode 0600 in the temporary directory&#8221;</p>
<p>Otherwise it should fit your bill,<br />
Regards</p>
]]></content:encoded>
	</item>
</channel>
</rss>

