deflate parts of a file

S

sid

I need to compress parts of a file, say some sections of an xml file
while leaving others as ASCII on the ouput stream. I took the deflate
example from cpan and started gathering all lines of a section in a
string and then doing one deflate, ouput, flush and output the
compressed section. But this doesn't seem to be working. I am seeing
"use of uninitialized values" warnings and the final output file
doesn't look right. I would see some compressed data then a whole bunch
of xml without any compressed data in between and so forth. The
compress method has a horrible performance. It actually made the file
much bigger. Hence I only want to use the deflate method. It works fine
on the whole file. But I want to use it on sections of a file. Are
there examples that someone can point me to?

thanks
SS
 
P

Paul Marquess

sid said:
I need to compress parts of a file, say some sections of an xml file
while leaving others as ASCII on the ouput stream. I took the deflate
example from cpan

Which deflate example are you referring to?
and started gathering all lines of a section in a
string and then doing one deflate, ouput, flush and output the
compressed section. But this doesn't seem to be working. I am seeing
"use of uninitialized values" warnings and the final output file
doesn't look right.
I would see some compressed data then a whole bunch
of xml without any compressed data in between and so forth.

Can you post some code please?
The
compress method has a horrible performance. It actually made the file
much bigger.
Hence I only want to use the deflate method. It works fine
on the whole file.

Compression isn't worth the effort on small strings. Ending up with
something bigger is one of the main reasons for not doing it.
But I want to use it on sections of a file. Are
there examples that someone can point me to?

Paul
 
S

sid

use Compress::Zlib ;
binmode STDIN;
binmode STDOUT;
$x = deflateInit()
or die "Cannot create a deflation stream\n" ;
while (<>)
{
($output, $status) = $x->deflate($_) ;


$status == Z_OK
or die "deflation failed\n" ;
print $output ;
}
($output, $status) = $x->flush() ;
$status == Z_OK
or die "deflation failed\n" ;
print $output ;
--------------------------------------------------------------
My code is based on this:
while(<>){
if(begin_xmltag)then set flag
if(flag){$string.=$_}
else {print $_}
if(end_xmltag) {
set output to compressed string using deflate procedre
print $output
do a flush on the deflate stream
set string to null
}
}
 
P

Paul Marquess

sid said:
use Compress::Zlib ;
binmode STDIN;
binmode STDOUT;
$x = deflateInit()
or die "Cannot create a deflation stream\n" ;
while (<>)
{
($output, $status) = $x->deflate($_) ;


$status == Z_OK
or die "deflation failed\n" ;
print $output ;
}
($output, $status) = $x->flush() ;
$status == Z_OK
or die "deflation failed\n" ;
print $output ;

OK, *that* deflate :)
--------------------------------------------------------------
My code is based on this:
while(<>){
if(begin_xmltag)then set flag
if(flag){$string.=$_}
else {print $_}
if(end_xmltag) {
set output to compressed string using deflate procedre
print $output
do a flush on the deflate stream

After the flush, do you then print the output that the flush has generated?
set string to null
}
}

Without seeing the actual code its difficult to tell the problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top