Forum: Ruby unix zcat with ruby?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
48b215dad1a569d01dabbd2e8dddf570?d=identicon&s=25 music (Guest)
on 2007-04-23 15:41
(Received via mailing list)
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?
703fbc991fd63e0e1db54dca9ea31b53?d=identicon&s=25 Robert Dober (Guest)
on 2007-04-23 16:16
(Received via mailing list)
On 4/23/07, music <music@musi.ca> wrote:
> 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?
>
>
Sure is
ARGF
HTH
R.
48b215dad1a569d01dabbd2e8dddf570?d=identicon&s=25 music (Guest)
on 2007-04-24 09:05
(Received via mailing list)
Robert Dober wrote:
> On 4/23/07, music <music@musi.ca> wrote:
>> 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?
>>
>>
> Sure is
> ARGF

ARGF ok, but how can I pass ARGF to a method?
703fbc991fd63e0e1db54dca9ea31b53?d=identicon&s=25 Robert Dober (Guest)
on 2007-04-24 09:30
(Received via mailing list)
On 4/24/07, music <music@musi.ca> wrote:
> 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.
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2007-04-24 09:35
(Received via mailing list)
On 24.04.2007 09:04, music wrote:
> ARGF ok, but how can I pass ARGF to a method?
What???


some_method(ARGF)

  robert
48b215dad1a569d01dabbd2e8dddf570?d=identicon&s=25 music (Guest)
on 2007-04-24 09:45
(Received via mailing list)
Robert Dober wrote:
>>
>   end
> end

Great!!! and if input files are in gzip format? how can I read them?
703fbc991fd63e0e1db54dca9ea31b53?d=identicon&s=25 Robert Dober (Guest)
on 2007-04-24 09:55
(Received via mailing list)
On 4/24/07, music <music@musi.ca> wrote:
> >> > ARGF
> >    whatever
> >   end
> > end
>
> Great!!! and if input files are in gzip format? how can I read them?
>
>
http://www.ruby-doc.org/stdlib/libdoc/zlib/rdoc/index.html
48b215dad1a569d01dabbd2e8dddf570?d=identicon&s=25 music (Guest)
on 2007-04-24 10:17
(Received via mailing list)
Robert Dober wrote:
>> >> > Sure is
>> >     | line |
>> >    whatever
>> >   end
>> > end
>>
>> Great!!! and if input files are in gzip format? how can I read them?
>>
>>
> http://www.ruby-doc.org/stdlib/libdoc/zlib/rdoc/index.html
>

Yes but can I use ARGF with zlib?
48b215dad1a569d01dabbd2e8dddf570?d=identicon&s=25 music (Guest)
on 2007-04-24 12:26
(Received via mailing list)
music wrote:
>>> >> >>
>>> >   ARGF.each_line do
>
> Yes but can I use ARGF with zlib?

Any help? I'm searching in Zlib::GzipReader class but I can't undestand
how I can use with ARGF.
703fbc991fd63e0e1db54dca9ea31b53?d=identicon&s=25 Robert Dober (Guest)
on 2007-04-24 12:41
(Received via mailing list)
On 4/24/07, music <music@musi.ca> wrote:
> >>> >> >>
> >>> > def my_method
> >>
> >
> > Yes but can I use ARGF with zlib?
>
> 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
703fbc991fd63e0e1db54dca9ea31b53?d=identicon&s=25 Robert Dober (Guest)
on 2007-04-24 12:53
(Received via mailing list)
>
> 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.
48b215dad1a569d01dabbd2e8dddf570?d=identicon&s=25 music (Guest)
on 2007-04-24 13:01
(Received via mailing list)
Robert Dober wrote:
>>
>> 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.
>

Sorry for my newbie condition but I don't understand.
753dcb78b3a3651127665da4bed3c782?d=identicon&s=25 Brian Candler (Guest)
on 2007-04-24 13:13
(Received via mailing list)
On Tue, Apr 24, 2007 at 07:52:41PM +0900, Robert Dober wrote:
> >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,

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.
703fbc991fd63e0e1db54dca9ea31b53?d=identicon&s=25 Robert Dober (Guest)
on 2007-04-24 13:45
(Received via mailing list)
On 4/24/07, Brian Candler <B.Candler@pobox.com> wrote:
> On Tue, Apr 24, 2007 at 07:52:41PM +0900, Robert Dober wrote:
> > >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,
>
> 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
This topic is locked and can not be replied to.