unix zcat with ruby?

M

music

I have to read in many files.
I prefer to concat those files and reading only one large file.
There is a way like unix zcat?
 
R

Robert Dober

ARGF ok, but how can I pass ARGF to a method?
As a global constant it is visible anywhere, you can thus simply do
things like this

def my_method
ARGF.each_line do
| line |
whatever
end
end

R.
 
M

music

Robert said:
As a global constant it is visible anywhere, you can thus simply do
things like this

def my_method
ARGF.each_line do
| line |
whatever
end
end

Great!!! and if input files are in gzip format? how can I read them?
 
R

Robert Dober

Any help? I'm searching in Zlib::GzipReader class but I can't undestand
how I can use with ARGF.
Something like this
ruby -rzlib -e 'reader = Zlib::GzipReader.new(ARGF);reader.each_line
do |x| puts x end' xxx.gz
I discovered however that
Zlib::GzipReader.new(ARGF)
seems to ignore all but the first file in the argument list - unless I
did something stupid - that complicates matters slightly, you still
can do things like

ARGV.each do
| filename |
Zlib::GeipReader.open( filename) do
|gz|
gz.each_line ....
...
end
end

of course but this behavior surprises me a little bit, maybe you
should mine the Zlib doc for this.

Robert
 
R

Robert Dober

of course but this behavior surprises me a little bit,
forget what I said, I just switched my brain on
the concatenation of two gzipped streams is of course not a gzipped stream,
Zlib does well to inflate the first one, maybe a warning would be nice.
R.
 
M

music

Robert said:
forget what I said, I just switched my brain on
the concatenation of two gzipped streams is of course not a gzipped stream,
Zlib does well to inflate the first one, maybe a warning would be nice.
R.

Sorry for my newbie condition but I don't understand.
 
B

Brian Candler

forget what I said, I just switched my brain on
the concatenation of two gzipped streams is of course not a gzipped stream,

But the standalone gzip program handles this:

$ (echo "foo" | gzip -c; echo "bar" | gzip -c) | gzip -dc
foo
bar
$

It enables you to grow a gzip file without having to entirely decompress and
recompress what's already there.
 
R

Robert Dober

But the standalone gzip program handles this:
zcat does too, which is nice of course.
But this is an extra feature and I did not want to criticize zlib for
not implementing this extra feature, maybe someone will provide a
patch to ruby-core ;)
$ (echo "foo" | gzip -c; echo "bar" | gzip -c) | gzip -dc
foo
bar
$
It enables you to grow a gzip file without having to entirely decompress and
recompress what's already there.
Yeah I just tested this, as I use gzip only with tar.
Hmm does that mean that I was wrong that the concatenation of two
gzipped streams is not a gzipped stream?
Nahh, that surely is just an underlying feature of gzip (and bzip2 for
that matter).
Gotta look that after...Cheers
Robert
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top