<?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: Utl_compress, gzip and zlib</title>
	<atom:link href="http://technology.amis.nl/blog/7626/utl_compress-gzip-and-zlib/feed" rel="self" type="application/rss+xml" />
	<link>http://technology.amis.nl/blog/7626/utl_compress-gzip-and-zlib</link>
	<description>Weblog for the AMIS Technology corner</description>
	<lastBuildDate>Fri, 10 Feb 2012 16:47:37 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Anton Scheffer</title>
		<link>http://technology.amis.nl/blog/7626/utl_compress-gzip-and-zlib/comment-page-1#comment-481488</link>
		<dc:creator>Anton Scheffer</dc:creator>
		<pubDate>Sat, 19 Nov 2011 11:42:05 +0000</pubDate>
		<guid isPermaLink="false">http://technology.amis.nl/blog/?p=7626#comment-481488</guid>
		<description>@orodri
I doubt it, but then again, I&#039;ve never tried it.</description>
		<content:encoded><![CDATA[<p>@orodri<br />
I doubt it, but then again, I&#8217;ve never tried it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: orodri</title>
		<link>http://technology.amis.nl/blog/7626/utl_compress-gzip-and-zlib/comment-page-1#comment-481487</link>
		<dc:creator>orodri</dc:creator>
		<pubDate>Fri, 18 Nov 2011 21:00:46 +0000</pubDate>
		<guid isPermaLink="false">http://technology.amis.nl/blog/?p=7626#comment-481487</guid>
		<description>hello!
I want to read 7zip files with LZMA format
it is posible with this code? plsql</description>
		<content:encoded><![CDATA[<p>hello!<br />
I want to read 7zip files with LZMA format<br />
it is posible with this code? plsql</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: William Robertson</title>
		<link>http://technology.amis.nl/blog/7626/utl_compress-gzip-and-zlib/comment-page-1#comment-481380</link>
		<dc:creator>William Robertson</dc:creator>
		<pubDate>Fri, 28 Oct 2011 13:45:44 +0000</pubDate>
		<guid isPermaLink="false">http://technology.amis.nl/blog/?p=7626#comment-481380</guid>
		<description>Awesome - now .3 seconds for same 27K blob. Thanks! I&#039;d tried to do something similar with a second pass to sweep up the trailing section, but couldn&#039;t get it to work.</description>
		<content:encoded><![CDATA[<p>Awesome &#8211; now .3 seconds for same 27K blob. Thanks! I&#8217;d tried to do something similar with a second pass to sweep up the trailing section, but couldn&#8217;t get it to work.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anton Scheffer</title>
		<link>http://technology.amis.nl/blog/7626/utl_compress-gzip-and-zlib/comment-page-1#comment-481379</link>
		<dc:creator>Anton Scheffer</dc:creator>
		<pubDate>Fri, 28 Oct 2011 11:47:07 +0000</pubDate>
		<guid isPermaLink="false">http://technology.amis.nl/blog/?p=7626#comment-481379</guid>
		<description>As explained in the blog uncompressing has to be done byte for byte. You can speed it up by doing it twice! First with a large buffer until you fail, and a second time with a large buffer and stop just before the end and finish then byte for byte. Something like

function zlib_decompress( p_src in blob )
return blob
is
  t_out blob;
  t_tmp blob;
  t_buf raw(8132);
  t_buffer raw(1);
  t_hdl binary_integer;
  t_max_loops pls_integer;
  t_s1 pls_integer; -- s1 part of adler32 checksum
  t_last_chr pls_integer;
begin
  dbms_lob.createtemporary( t_out, true );
  dbms_lob.createtemporary( t_tmp, true );
  t_tmp := hextoraw( &#039;1F8B0800000000000003&#039; ); -- gzip header
  dbms_lob.copy( t_tmp, p_src, dbms_lob.getlength( p_src ) - 2 - 4, 11, 3 );
  dbms_lob.append( t_tmp, hextoraw( &#039;0000000000000000&#039; ) ); -- add a fake trailer
  t_hdl := utl_compress.lz_uncompress_open( t_tmp );
  t_s1 := 1;
  t_max_loops := 0;
  loop
    begin
      utl_compress.lz_uncompress_extract( t_hdl, t_buf );
      dbms_lob.append( t_out, t_buf );
      for i in 1 .. 8132
      loop
        t_s1 := mod( t_s1 + utl_raw.cast_to_binary_integer( utl_raw.substr( t_buf, i, 1 ) ), 65521 );
      end loop;
      t_max_loops := t_max_loops + 1;
    exception
      when others
      then
        if utl_compress.isopen( t_hdl )
        then
          utl_compress.lz_uncompress_close( t_hdl );
        end if;
        t_hdl := utl_compress.lz_uncompress_open( t_tmp );
        exit;
    end;
  end loop;
  for i in 1 .. t_max_loops
  loop
    utl_compress.lz_uncompress_extract( t_hdl, t_buf );
  end loop;
  loop
    begin
      utl_compress.lz_uncompress_extract( t_hdl, t_buffer );
    exception
      when others
      then
        exit;
    end;
    dbms_lob.append( t_out, t_buffer );
    t_s1 := mod( t_s1 + to_number( rawtohex( t_buffer ), &#039;xx&#039; ), 65521 );
  end loop;
  t_last_chr := to_number( dbms_lob.substr( p_src, 2, dbms_lob.getlength( p_src ) - 1 ), &#039;0XXX&#039;) - t_s1;
  if t_last_chr &lt; 0
  then
    t_last_chr := t_last_chr + 65521;
  end if;
    dbms_output.put_line( t_s1 &#124;&#124; &#039;x&#039; &#124;&#124; t_last_chr );
  dbms_lob.append( t_out, hextoraw( to_char( t_last_chr, &#039;fm0X&#039; ) ) );
  if utl_compress.isopen( t_hdl )
  then
    utl_compress.lz_uncompress_close( t_hdl );
  end if;
  dbms_lob.freetemporary( t_tmp );
  return t_out;
end;</description>
		<content:encoded><![CDATA[<p>As explained in the blog uncompressing has to be done byte for byte. You can speed it up by doing it twice! First with a large buffer until you fail, and a second time with a large buffer and stop just before the end and finish then byte for byte. Something like</p>
<p>function zlib_decompress( p_src in blob )<br />
return blob<br />
is<br />
  t_out blob;<br />
  t_tmp blob;<br />
  t_buf raw(8132);<br />
  t_buffer raw(1);<br />
  t_hdl binary_integer;<br />
  t_max_loops pls_integer;<br />
  t_s1 pls_integer; &#8212; s1 part of adler32 checksum<br />
  t_last_chr pls_integer;<br />
begin<br />
  dbms_lob.createtemporary( t_out, true );<br />
  dbms_lob.createtemporary( t_tmp, true );<br />
  t_tmp := hextoraw( &#8216;1F8B0800000000000003&#8242; ); &#8212; gzip header<br />
  dbms_lob.copy( t_tmp, p_src, dbms_lob.getlength( p_src ) &#8211; 2 &#8211; 4, 11, 3 );<br />
  dbms_lob.append( t_tmp, hextoraw( &#8216;0000000000000000&#8242; ) ); &#8212; add a fake trailer<br />
  t_hdl := utl_compress.lz_uncompress_open( t_tmp );<br />
  t_s1 := 1;<br />
  t_max_loops := 0;<br />
  loop<br />
    begin<br />
      utl_compress.lz_uncompress_extract( t_hdl, t_buf );<br />
      dbms_lob.append( t_out, t_buf );<br />
      for i in 1 .. 8132<br />
      loop<br />
        t_s1 := mod( t_s1 + utl_raw.cast_to_binary_integer( utl_raw.substr( t_buf, i, 1 ) ), 65521 );<br />
      end loop;<br />
      t_max_loops := t_max_loops + 1;<br />
    exception<br />
      when others<br />
      then<br />
        if utl_compress.isopen( t_hdl )<br />
        then<br />
          utl_compress.lz_uncompress_close( t_hdl );<br />
        end if;<br />
        t_hdl := utl_compress.lz_uncompress_open( t_tmp );<br />
        exit;<br />
    end;<br />
  end loop;<br />
  for i in 1 .. t_max_loops<br />
  loop<br />
    utl_compress.lz_uncompress_extract( t_hdl, t_buf );<br />
  end loop;<br />
  loop<br />
    begin<br />
      utl_compress.lz_uncompress_extract( t_hdl, t_buffer );<br />
    exception<br />
      when others<br />
      then<br />
        exit;<br />
    end;<br />
    dbms_lob.append( t_out, t_buffer );<br />
    t_s1 := mod( t_s1 + to_number( rawtohex( t_buffer ), &#8216;xx&#8217; ), 65521 );<br />
  end loop;<br />
  t_last_chr := to_number( dbms_lob.substr( p_src, 2, dbms_lob.getlength( p_src ) &#8211; 1 ), &#8216;0XXX&#8217;) &#8211; t_s1;<br />
  if t_last_chr &lt; 0<br />
  then<br />
    t_last_chr := t_last_chr + 65521;<br />
  end if;<br />
    dbms_output.put_line( t_s1 || &#39;x&#39; || t_last_chr );<br />
  dbms_lob.append( t_out, hextoraw( to_char( t_last_chr, &#39;fm0X&#39; ) ) );<br />
  if utl_compress.isopen( t_hdl )<br />
  then<br />
    utl_compress.lz_uncompress_close( t_hdl );<br />
  end if;<br />
  dbms_lob.freetemporary( t_tmp );<br />
  return t_out;<br />
end;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: William Robertson</title>
		<link>http://technology.amis.nl/blog/7626/utl_compress-gzip-and-zlib/comment-page-1#comment-481378</link>
		<dc:creator>William Robertson</dc:creator>
		<pubDate>Fri, 28 Oct 2011 10:17:58 +0000</pubDate>
		<guid isPermaLink="false">http://technology.amis.nl/blog/?p=7626#comment-481378</guid>
		<description>Thanks! That brings it down to around a second. Is there a sensible way to increase the size of  the raw buffer? That seemed to help as well but I get out of my depth rather quickly when it comes to the raw/hex/number/string conversions.</description>
		<content:encoded><![CDATA[<p>Thanks! That brings it down to around a second. Is there a sensible way to increase the size of  the raw buffer? That seemed to help as well but I get out of my depth rather quickly when it comes to the raw/hex/number/string conversions.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anton Scheffer</title>
		<link>http://technology.amis.nl/blog/7626/utl_compress-gzip-and-zlib/comment-page-1#comment-481372</link>
		<dc:creator>Anton Scheffer</dc:creator>
		<pubDate>Thu, 27 Oct 2011 17:32:47 +0000</pubDate>
		<guid isPermaLink="false">http://technology.amis.nl/blog/?p=7626#comment-481372</guid>
		<description>@&lt;strong&gt;William Robertson
&lt;/strong&gt;If you want to make this code a lot faster, just change the parameter &quot;cache&quot; of the calls to dbms_lob.createtemporary to true. No idea why I set it to false.</description>
		<content:encoded><![CDATA[<p>@<strong>William Robertson<br />
</strong>If you want to make this code a lot faster, just change the parameter &#8220;cache&#8221; of the calls to dbms_lob.createtemporary to true. No idea why I set it to false.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: William Robertson</title>
		<link>http://technology.amis.nl/blog/7626/utl_compress-gzip-and-zlib/comment-page-1#comment-481370</link>
		<dc:creator>William Robertson</dc:creator>
		<pubDate>Thu, 27 Oct 2011 15:42:33 +0000</pubDate>
		<guid isPermaLink="false">http://technology.amis.nl/blog/?p=7626#comment-481370</guid>
		<description>Pity it has to read one byte at a time - it&#039;s taking about a minute for a 27K blob. I tried making t_buffer raw(2) and adjusting thecorresponding  &#039;XX&#039; formats and it&#039;s twice as fast, but it loses the final character.</description>
		<content:encoded><![CDATA[<p>Pity it has to read one byte at a time &#8211; it&#8217;s taking about a minute for a 27K blob. I tried making t_buffer raw(2) and adjusting thecorresponding  &#8216;XX&#8217; formats and it&#8217;s twice as fast, but it loses the final character.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anton Scheffer</title>
		<link>http://technology.amis.nl/blog/7626/utl_compress-gzip-and-zlib/comment-page-1#comment-481289</link>
		<dc:creator>Anton Scheffer</dc:creator>
		<pubDate>Tue, 11 Oct 2011 07:13:22 +0000</pubDate>
		<guid isPermaLink="false">http://technology.amis.nl/blog/?p=7626#comment-481289</guid>
		<description>@Peter
The zip-format supports a lot of different compression methods. With my plsql-code I support only two methods. 
And some extensions to the zip-format support &quot;big-files&quot;. That something I don&#039;t handle too.</description>
		<content:encoded><![CDATA[<p>@Peter<br />
The zip-format supports a lot of different compression methods. With my plsql-code I support only two methods.<br />
And some extensions to the zip-format support &#8220;big-files&#8221;. That something I don&#8217;t handle too.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter</title>
		<link>http://technology.amis.nl/blog/7626/utl_compress-gzip-and-zlib/comment-page-1#comment-481288</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Tue, 11 Oct 2011 06:56:23 +0000</pubDate>
		<guid isPermaLink="false">http://technology.amis.nl/blog/?p=7626#comment-481288</guid>
		<description>I have a zip file in my blob field.. When I try to uncompress it i get error
ORA-06502: PL/SQL: numeric or value error: hex to raw conversion error
ORA-06512: at line 39
ORA-06512: at line 63
The problem is also when i like to unzip it in java.. I get: java.util.zip.ZipException: invalid entry size
I can normaly open the file with winzip.. or winrar..
 </description>
		<content:encoded><![CDATA[<p>I have a zip file in my blob field.. When I try to uncompress it i get error<br />
ORA-06502: PL/SQL: numeric or value error: hex to raw conversion error<br />
ORA-06512: at line 39<br />
ORA-06512: at line 63<br />
The problem is also when i like to unzip it in java.. I get: java.util.zip.ZipException: invalid entry size<br />
I can normaly open the file with winzip.. or winrar..<br />
 </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marco</title>
		<link>http://technology.amis.nl/blog/7626/utl_compress-gzip-and-zlib/comment-page-1#comment-363005</link>
		<dc:creator>Marco</dc:creator>
		<pubDate>Sun, 14 Mar 2010 04:04:08 +0000</pubDate>
		<guid isPermaLink="false">http://technology.amis.nl/blog/?p=7626#comment-363005</guid>
		<description>:-)
 </description>
		<content:encoded><![CDATA[<p> <img src='http://technology.amis.nl/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /><br />
 </p>
]]></content:encoded>
	</item>
</channel>
</rss>

