class DbSucker::Application::SklavenTreiber::Worker::IO::FileGunzip

Attributes

preserve_original[RW]
use_tmp[RW]

Public Instance Methods

gunzip!(opts = {}) click to toggle source
# File lib/db_sucker/application/sklaven_treiber/worker/io/file_gunzip.rb, line 19
def gunzip! opts = {}
  opts = opts.reverse_merge(tries: 1, read_size: @read_size)
  prepare_local_destination

  execute(opts.slice(:tries).merge(sleep_error: 3)) do
    @tmploc   = @use_tmp ? "#{@local}.tmp" : @local
    @in_file  = File.new(@remote, "rb")
    @out_file = File.new(@tmploc, "wb")
    @filesize = @in_file.size if @filesize.zero?

    @state = :decompressing
    gz = Zlib::GzipReader.new(@in_file)
    begin
      while buf = gz.read(opts[:read_size])
        if !@closing && @abort_if.call(self)
          @closing = true
          break
        end

        @offset += [opts[:read_size], @filesize - @offset].min
        @out_file.syswrite(buf)
        GC.start if @offset % GC_FORCE_RATE == 0
      end
    ensure
      @state = :finishing
      gz.close
      @out_file.close
    end

    FileUtils.mv(@tmploc, @local) if @use_tmp
    File.unlink(@remote) unless @preserve_original
  end
end
init() click to toggle source
# File lib/db_sucker/application/sklaven_treiber/worker/io/file_gunzip.rb, line 10
def init
  @label = "decompressing"
  @entity = "decompress"
  @use_tmp = true
  @preserve_original = false
  @local ||= "#{File.dirname(@remote)}/#{File.basename(@remote, ".gz")}"
  @throughput.categories << :io << :io_gunzip
end