Method: S3sync::ProgressStream#read

Defined in:
lib/s3sync/HTTPStreaming.rb

#read(i) ⇒ Object

need to catch reads and writes so we can count what’s being transferred



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/s3sync/HTTPStreaming.rb', line 65

def read(i)
  res = @innerStream.read(i)
  @transferred += res.respond_to?(:length) ? res.length : 0
  now = Time.new
  if(now - @last > 1) # don't do this oftener than once per second

    @printed = true
          begin
             $stdout.printf("\rProgress: %db  %db/s  %s       ", @transferred, (@transferred/(now - @start)).floor, 
                @total > 0? (100 * @transferred/@total).floor.to_s + "%" : ""  
             )
          rescue FloatDomainError
             #wtf?

          end
    $stdout.flush
    @last = now
  end
  res
end