Class: TTK::Fetchers::Server::Sender
- Includes:
- DRb::DRbUndumped
- Defined in:
- lib/ttk/fetchers/server/sender.rb
Constant Summary collapse
- BLOCK_SIZE =
1024
Instance Method Summary collapse
-
#initialize(resource, receiver) ⇒ Sender
constructor
A new instance of Sender.
- #send ⇒ Object
- #stat ⇒ Object
Constructor Details
#initialize(resource, receiver) ⇒ Sender
Returns a new instance of Sender.
19 20 21 22 23 24 25 26 27 |
# File 'lib/ttk/fetchers/server/sender.rb', line 19 def initialize(resource, receiver) @resource = resource unless @resource.exist? raise(Errno::ENOENT, "`#@resource' - no such resource") end @receiver = receiver @md5sum = Digest::MD5.new @success = nil end |
Instance Method Details
#send ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ttk/fetchers/server/sender.rb', line 29 def send if @success.nil? @t0 = Time.now @resource.open do |f| until f.eof? str = f.read(BLOCK_SIZE) @md5sum << str @receiver.recv(str) end @success = @receiver.stop(@md5sum.to_s) end @enlapsed_time = DTime.new(Time.now - @t0) @success end end |
#stat ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ttk/fetchers/server/sender.rb', line 45 def stat unless @success.nil? { :resource => @resource, :enlapsed_time => @enlapsed_time, :md5sum => @md5sum.to_s, :success => @success } end end |