class SqlToCsvStream::GzipWrapper

Public Class Methods

new(source) click to toggle source
# File lib/sql_to_csv_stream/gzip_wrapper.rb, line 7
def initialize(source)
  @source = source
end

Public Instance Methods

each(&block) click to toggle source
# File lib/sql_to_csv_stream/gzip_wrapper.rb, line 11
def each(&block)
  @destination = block
  # Zlib::GzipWriter needs to get passed an object that implements the #write method.
  # this is why we implement the #write method further down
  # while assigning the stream we need to write to in an instance variable to be used there.
  @zipper = Zlib::GzipWriter.new(self)
  @source.each do |string|
    @zipper.write(string)
  end
ensure
  @zipper.close
end
write(zipped_string) click to toggle source

called indirectly by Zlib::GzipWriter

# File lib/sql_to_csv_stream/gzip_wrapper.rb, line 25
def write(zipped_string)
  @destination.yield(zipped_string)
end