open a gzipped file( a.gz) with out uncompressing it 
Author Message
 open a gzipped file( a.gz) with out uncompressing it

How can I open a gziiped file with out uncompressing a 2 gig .gz file.

Is there any way to do this with out using perl modules.

Thanks
Roy



Fri, 23 Apr 2004 06:37:30 GMT  
 open a gzipped file( a.gz) with out uncompressing it

Quote:

> How can I open a gziiped file with out uncompressing a 2 gig .gz file.

man zcat

my $file = 'somefile.gz';       # Be careful in a CGI script
open (FILE, "zcat '$file' |") || die "Huh? $!";

Chris



Sat, 24 Apr 2004 01:26:47 GMT  
 open a gzipped file( a.gz) with out uncompressing it

Quote:

> How can I open a gziiped file with out uncompressing a 2 gig .gz
> file.

Huh?  You can read a file without decompressing it in exactly the same
way as you would eat a carrot without cooking it.

PSI::ESP tells me you want to read the _uncompressed_ data
uncompressing the file on the fly:

open(FILE,"zcat somefile.gz|") or die "Open failed: $!";
# do stuff wtih file.
close(FILE) or dir "Close on pipe failed: $?";

--
     \\   ( )
  .  _\\__[oo

 .  l___\\
  # ll  l\\
 ###LL  LL\\



Sat, 24 Apr 2004 03:23:11 GMT  
 open a gzipped file( a.gz) with out uncompressing it

Quote:
> How can I open a gziiped file with out uncompressing a 2 gig .gz file.

> Is there any way to do this with out using perl modules.

I'd suggest using Archive::Tar, basing on Compress::Zlib.
Be sure to read the installation for both - you need an external
lib for Compress::Zlib to work.

I've never done it myself, but it looks like Archive::Tar need not
gunzip the whole file in order to proceed - by using the sequential
access to the gzip stream that is possible with Compress::Zlib.

HTH,
        Vassilii
P.S. If what I point you to here is new for you, great. But, please
use CPAN yourself next time - there's a top-level category there,
http://cpan.org/modules/by-category/17_Archiving_and_Compression/
where these can be easily found...

If you knew it already - you should have probably written in your orig.
posting that Archive::Tar didn't help you.

V.



Sat, 24 Apr 2004 02:26:42 GMT  
 open a gzipped file( a.gz) with out uncompressing it

Quote:

> How can I open a gziiped file with out uncompressing a 2 gig .gz file.

> Is there any way to do this with out using perl modules.

Assuming you don't want to decompress it, there's no difference between a
.gz file and any others.

open SOMEFILE, 'whatever.gz';

If you want to actually read the compressed data, then you'll have to use a
Perl module called Compress::Zlib.

But you don't have to decompress the whole thing; you can just decompress a
buffer at a time and process it (from the manpage):

           $gz = gzopen($filename or filehandle, $mode) ;
           $bytesread = $gz->gzread($buffer [,$size]) ;
           $bytesread = $gz->gzreadline($line) ;
           $byteswritten = $gz->gzwrite($buffer) ;
           $status = $gz->gzflush($flush) ;
           $status = $gz->gzclose() ;
           $errstring = $gz->gzerror() ;
           $gzerrno



Sat, 24 Apr 2004 02:36:05 GMT  
 open a gzipped file( a.gz) with out uncompressing it

Quote:

>If you want to actually read the compressed data, then you'll have to use a
>Perl module called Compress::Zlib.

Not necessarily.  There are at least three modules on CPAN for
transparently reading gzipped files; I eventually picked IO::Zlib as
the most sensible-looking.  There is also some voodoo module using
perl 5.7's PerlIO layer.  It would be nice to rationalize the various
gzip-reading modules into one or two by deprecating some of them - but
I can appreciate this is easier said than done :-(.

I'm still looking for an elegant and cheap (and
not-requiring-bleeding-edge-perl) way to _transparently_ handle
gzipped files as well as ordinary ones.  With IO::Zlib I ended up
running file(1) on each input file and seeing whether the output
contains 'gzip' - which rather negates any performance increase from
not forking a gzip process.

--

Finger for PGP key



Sat, 24 Apr 2004 19:09:45 GMT  
 open a gzipped file( a.gz) with out uncompressing it

Quote:

> How can I open a gziiped file with out uncompressing a 2 gig .gz file.

Compress::Zlib is probably your best bet.

Quote:
> Is there any way to do this with out using perl modules.

You could read the output of the `gzip' program:

    open FOO, "gzip -dc $myfile |" or die "gzip open: $!\n";
    # Now read FOO line-by-line, e.g.:
    print while <FOO>;

--

Compugen Ltd.          |   +++ THIS SPACE TO LET +++    \ We recycle all our Hz
72 Pinhas Rosen St.    |Tel: +972-3-7658117 (Main office)`---------------------
Tel-Aviv 69512, ISRAEL |Fax: +972-3-7658555    http://3w.compugen.co.il/~ariels



Sat, 24 Apr 2004 18:02:24 GMT  
 open a gzipped file( a.gz) with out uncompressing it

Quote:

> I'm still looking for an elegant and cheap (and
> not-requiring-bleeding-edge-perl) way to _transparently_ handle
> gzipped files as well as ordinary ones.

"zcat -f" (from the gzip family; use "gunzip -f < {file}" if you prefer)
will uncomplainingly act as cat if its input isn't compressed.

Chris



Sun, 25 Apr 2004 00:02:33 GMT  
 open a gzipped file( a.gz) with out uncompressing it


Quote:
>I'm still looking for an elegant and cheap (and
>not-requiring-bleeding-edge-perl) way to _transparently_ handle
>gzipped files as well as ordinary ones.  With IO::Zlib I ended up
>running file(1) on each input file and seeing whether the output
>contains 'gzip' - which rather negates any performance increase from
>not forking a gzip process.

You don't need to fork off an external process just to decide whether
the first few bytes of a given file look like a gzip archive.

I direct you to /etc/magic, which has the following:

    0       string          \037\213        gzip compressed data
    >2      byte            8               - deflate method
    >3      byte            &0x1            , ascii
    >3      byte            &0x2            , continuation
    >3      byte            &0x4            , extra field
    >3      byte            &0x8            , original file name
    >3      byte            &0x10           , comment
    >3      byte            &0x20           , encrypted
    >8      byte            2               , max compression
    >8      byte            4               , max speed

        -Joe
--
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.



Sun, 25 Apr 2004 05:03:39 GMT  
 open a gzipped file( a.gz) with out uncompressing it

Quote:

>>I'm still looking for an elegant and cheap (and
>>not-requiring-bleeding-edge-perl) way to _transparently_ handle
>>gzipped files as well as ordinary ones.

>"zcat -f" (from the gzip family; use "gunzip -f < {file}" if you
>prefer) will uncomplainingly act as cat if its input isn't
>compressed.

Useful; but I'd like to find a single-process answer (no external
gzip).  I think the PerlIO-based zlib module did the job, but perl 5.7
is still a long way off for me :-(.

--

Finger for PGP key



Sun, 25 Apr 2004 05:33:39 GMT  
 open a gzipped file( a.gz) with out uncompressing it

Quote:

>>I'm still looking for an elegant and cheap (and
>>not-requiring-bleeding-edge-perl) way to _transparently_ handle
>>gzipped files as well as ordinary ones.  With IO::Zlib I ended up
>>running file(1) on each input file
>You don't need to fork off an external process just to decide whether
>the first few bytes of a given file look like a gzip archive.

>I direct you to /etc/magic,

That still requires (a) knowledge of the gzip format and (b) opening
the file twice, so it won't work for pipes.  But perhaps I am just
being picky now...

I'll implement something like that instead of running file(1) next
time I need to have transparent gunzipping.

--

Finger for PGP key



Sun, 25 Apr 2004 20:37:44 GMT  
 open a gzipped file( a.gz) with out uncompressing it

Quote:


> >>I'm still looking for an elegant and cheap (and
> >>not-requiring-bleeding-edge-perl) way to _transparently_ handle
> >>gzipped files as well as ordinary ones.  With IO::Zlib I ended up
> >>running file(1) on each input file
> >I direct you to /etc/magic,
> That still requires (a) knowledge of the gzip format

That's precisely what /etc/magic provides. And there's a nice man in
Japan who's written File::MMagic for just this purpose.

Quote:
> and (b) opening the file twice, so it won't work for pipes.

I can't think of an immediate solution, but feel sure you can persuade
Compress::Zlib to do the business if you try hard enough. I offer tied
file-handles as an existence proof that this is possible.

Quote:
> I'll implement something like that instead of running file(1) next
> time I need to have transparent gunzipping.

It can't be completely transparent you know. One day you'll find an
uncompressed file that looks just like a gzipped one (once in 65536
times, given random data).

Ian



Mon, 26 Apr 2004 18:54:54 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. Newbie seeks advice re engines

2. (no subject)

3. OPEN file inside a compress gz

4. A Win95 App for Opening *.tar.gz Files

5. how to extract gzipped file into a list

6. Processing text from gzipped file

7. info2www for gzipped files?

8. Perl code to unzip gzipped and pkzipped files ?

9. open FILE,$path || open FILE,$altpath;

10. Time outs and exit codes

11. Sockets, Time-outs, and Alarms

12. CLPB mFAQ - Essential reading for those new to the newsgroup

 

 
Powered by phpBB® Forum Software