<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: partial code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 07 Sep 2008 12:41:32 GMT</pubDate>
    <description>DZone Snippets: partial code</description>
    <item>
      <title>Reading corrupted/partial zip files in python</title>
      <link>http://snippets.dzone.com/posts/show/3790</link>
      <description>First a simple script for reading non-corruted zipfiles in python:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;filename = 'foo.zip'&lt;br /&gt;&lt;br /&gt;import zipfile&lt;br /&gt;&lt;br /&gt;z = zipfile.ZipFile(filename)&lt;br /&gt;&lt;br /&gt;for i in z.infolist():&lt;br /&gt;    print i.filename, i.file_size&lt;br /&gt;&lt;br /&gt;z.read('somefile')&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Next we use 'zip -FF foo.zip' to fix the zipfile, before reading it:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;filename = 'foo.zip'&lt;br /&gt;&lt;br /&gt;import zipfile&lt;br /&gt;&lt;br /&gt;try:&lt;br /&gt;    z = zipfile.ZipFile(filename)&lt;br /&gt;except zipfile.BadZipfile:&lt;br /&gt;    import commands&lt;br /&gt;    commands.getoutput('zip -FF '+filename)&lt;br /&gt;    z = zipfile.ZipFile(filename)&lt;br /&gt;&lt;br /&gt;for i in z.infolist():&lt;br /&gt;    print i.filename, i.file_size&lt;br /&gt;&lt;br /&gt;try: &lt;br /&gt;    z.read('somefile')&lt;br /&gt;except zipfile.BadZipfile:&lt;br /&gt;    print 'Bad CRC-32'&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In short: use 'zip -FF file.zip' to fix the file. It will restore the filelist.</description>
      <pubDate>Mon, 09 Apr 2007 20:35:31 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3790</guid>
      <author>zerrez (Johan Brinch)</author>
    </item>
    <item>
      <title>Render a partial to an instance variable</title>
      <link>http://snippets.dzone.com/posts/show/396</link>
      <description>Normally, if you call "render_partial" within a controller, nothing but the partial will be rendered.&lt;br /&gt;&lt;br /&gt;Occasionally, it is useful to render a partial to an instance variable as a string so that the view can still be rendered as normal, and the string can be passed in to the view.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;  add_variables_to_assigns&lt;br /&gt;  @content_for_navbar = @template.render_partial 'layouts/public_navbar'&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 19 Jun 2005 15:27:40 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/396</guid>
      <author>canadaduane (Duane Johnson)</author>
    </item>
  </channel>
</rss>
