Class: MultipleFilesGzipReader

Inherits:
Zlib::GzipReader
  • Object
show all
Includes:
Enumerable
Defined in:
lib/multiple_files_gzip_reader.rb,
lib/multiple_files_gzip_reader/version.rb

Constant Summary collapse

VERSION =
"0.4.0"

Instance Method Summary collapse

Constructor Details

#initialize(io, options = {}) ⇒ MultipleFilesGzipReader

Returns a new instance of MultipleFilesGzipReader.



7
8
9
10
# File 'lib/multiple_files_gzip_reader.rb', line 7

def initialize(io, options = {})
  @io = io
  @options = options
end

Instance Method Details

#each(*args, &block) ⇒ Object Also known as: each_line



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/multiple_files_gzip_reader.rb', line 16

def each(*args, &block)
  loop do
    gzip_reader = Zlib::GzipReader.new(io, options)

    gzip_reader.each_line(*args, &block)

    unused = gzip_reader.unused
    gzip_reader.finish

    io.pos -= unused ? unused.length : 0
    break if io.pos == io.size
  end
end

#readObject



36
37
38
# File 'lib/multiple_files_gzip_reader.rb', line 36

def read
  readlines.join
end

#readlinesObject



32
33
34
# File 'lib/multiple_files_gzip_reader.rb', line 32

def readlines
  map(&:to_s)
end

#rewindObject



12
13
14
# File 'lib/multiple_files_gzip_reader.rb', line 12

def rewind
  io.pos = 0
end