How do I get the entirety of an uncompressed gzip file using Zlib?

I am trying to uncompress a 823,000 line file, but I'm only receiving 26,000 lines of the file. I'm new to I/O and for some reason, not grasping why this is the case. Here is my code:

Zlib::GzipReader.open( file_path ) do |gz|
    puts gz.readlines.count
  end

Any direction would be appreciated. Thanks in advance.

Upvotes: 1

Views: 291

Answers (1)

Ok, so I managed to fix this. It turns out the server log file I was using had about 29 streams of data in it. Zlib::GzipReader only read the first one. In order to fix it, I had to loop through until all 29 streams had been read:

File.open(  file_path ) do |file|
    zio = file
    loop do
      io = Zlib::GzipReader.new( zio )
      uncompressed += io.read
      unused = io.unused # where I'm writing my file
      break if unused.nil?
      zio.pos -= unused.length
    end
  end

Upvotes: 3

Related Questions