class DbSucker::Application::SklavenTreiber::Worker::IO::Shasum

Attributes

result[RW]
sha[RW]

Public Instance Methods

init() click to toggle source
# File lib/db_sucker/application/sklaven_treiber/worker/io/file_shasum.rb, line 9
def init
  @label = "verifying"
  @entity = "verification"
  @sha ||= 1
  @throughput.categories.clear # IO read
end
verify!(opts = {}) click to toggle source
# File lib/db_sucker/application/sklaven_treiber/worker/io/file_shasum.rb, line 16
def verify! opts = {}
  opts = opts.reverse_merge(tries: 1, read_size: @read_size)

  execute(opts.slice(:tries).merge(sleep_error: 3)) do
    @in_file  = File.new(@remote, "rb")
    @filesize = @in_file.size

    @state = :working
    sha = "Digest::SHA#{@sha}".constantize.new
    buf = ""
    begin
      while @in_file.read(opts[:read_size], buf)
        if !@closing && @abort_if.call(self)
          @closing = true
          break
        end

        @offset += buf.bytesize
        sha << buf
        GC.start if @offset % GC_FORCE_RATE == 0
      end
    ensure
      @state = :finishing
      @in_file.close
      @result = sha.hexdigest
    end
  end
end