Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Compress::Zlib : what to do with the "in memory" data ?

by spq (Friar)
on Jan 07, 2005 at 17:31 UTC ( #420319=note: print w/replies, xml ) Need Help??

in reply to Compress::Zlib : what to do with the "in memory" data ?

I use Compress::Zlib for a number of in-memeory (un)compressions. I don't have any examples on hand for generating a file (I store to a database), but I did do that in tests to be sure the compressed data in the db could alternately be SELECT'd to a file and uncompressed with gzip.

my $zipped_raw = Compress::Zlib::memGzip($raw_genome); my $raw_genome = Compress::Zlib::memGunzip($zipped_raw);

So if you wanted to compress in memory and save to file based on your example:

$fu = "bla bla bla bla" ; $ba = Compress::Zlib::memGzip( $fu ) ; open FFF, ">ba.txt.gz" or die "$!" ; print FFF $ba; close (FFF) ;

However Compress::Zlib has methods that handle reading and writing gzip files built in.

$gz->gzwrite($buffer) ;

Which you may want to look at first if that's all your after.


Replies are listed 'Best First'.
Re^2: Compress::Zlib : what to do with the "in memory" data ?
by ZlR (Chaplain) on Jan 07, 2005 at 20:13 UTC
    Thanks a lot for you answer, gzwrite is interesting :
    open FFF, "<fu.txt" or die "$!" ; binmode FFF ; $gz = gzopen("fu.txt.gz", "wb") or die "gzerror" ; while ($buffer = <FFF>) { $gz->gzwrite($buffer) } close FFF ; $gz -> gzclose ;
    The resulting file is a valid gz file.
    I have to point out that i'm under win32, hence the binmode (otherwise newlines are washed out when i uncompress the file).

    But, i have a problem here : what i need to obtain is a .Z file and not a .gz .
    This might not be mandatory, but the resulting file is sent to someone else and i'll have to check if his programs can deal with a .gz .

    Do you know if Compress::Zlib will allow me to create a .Z file ? For exemple with inflate / deflate ? Or is zlib for gz compression only ?

    Thanks a lot,

    ZlR .

      Compress::Zlib and the underlying zlib library do not read or write .Z files. These are the files from the compress program, compressed using the once-patented LZW algorithm. zlib only does deflate, the algorithm used in gzip and zip files.

      AFAIK, there are no Perl modules for reading or writing .Z files. One option would be to pipe through zcat or gzip, which can read .Z files.

      Why do you want to use .Z files? .gz has better compression and is probably more widely supported now.

        Well , a .Z file is expected by some other scripts, which i do not control.
        I think "compress" was chosen because gzip was not available as a standard command on some unices.

        Update: Since Z compressed files can be opened by gzip, the scripts i communicate with will be able to use gunzip instead of compress , wich will allow them to read both .gz and .Z files.
        And i won't have to use a system call :)

        One more update: Since i also need to tar file with Archive::Tar I finally used the compression option this module provides, which creates a tar.gz . e.g :

        $objTar->write($myfile.tar.gz,1) ;
        Thx for your answers !

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://420319]
[thezip]: G'day all!
[perldigious]: Well, that and dodging the people who forget how ice works right away. :-)
[stevieb]: hey, thezip
[perldigious]: I don't miss having to drive up and down in elevation on roads that are iced over, I white knuckled gripping the steering wheel every time I had to where I used to live.
[perldigious]: So I don't envy you mountain guys if you have to drive in the winter, even with tire chains.
MidLifeXis waves.
[stevieb]: man, I absolutely LOVE driving in the worst winter conditions. In the mountainous roads, there are extremely few (if any) other drivers. I love the challenge. I've been doing extreme off-road my whole life, and as I said, I'm always well...
[stevieb]: ...prepared for even the very worst
Discipulus seems a part of the globe very unfrindly with Kawasaki riders..

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2016-12-06 16:44 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (112 votes). Check out past polls.