Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2003
    Posts
    9

    Unanswered: Perl - Compress::Zlib Module

    How do you use the Compress::Zlib module to uncompress gz files?

  2. #2
    Join Date
    Dec 2003
    Posts
    9
    I found some code that worked. It simply reads the the input .txt.gz file and renames it to .gz using zlib and file::basename. Pretty snazzy.

    source: http://mywebpages.comcast.net/habull...lutilities.htm
    ######## CODE ###########################################

    use Compress::Zlib;
    use File::Basename;
    use strict;

    fileparse_set_fstype($res_gz);
    my ($name,$path,$suffix) = fileparse($res_gz,"\.gz");

    my $gz = gzopen($res_gz, "rb") || die "failed to open file: $res_gz : $gzerrno\n";
    open (OUTFILE, ">$path$name") || die "failed to open file: $path$name";

    my $bytesread = 1;
    while ($bytesread > 0)
    {
    my $line;
    $bytesread = $gz->gzreadline($line);
    print OUTFILE $line;
    }
    if ($bytesread == -1)
    {
    print "Error: $gzerrno $gz-gzerror\n";
    }
    $gz->gzclose;
    close OUTFILE;

    ################################################## #######

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •