Permalink
Browse files

progress callbacks

git-svn-id: http://svn.jamisbuck.org/projects/net-scp/trunk@67 e3b5881a-3c0d-0410-9405-fd48df27f097
  • Loading branch information...
jamis committed Jul 29, 2007
1 parent b239321 commit bbfca3b688d61a81b8716ba1b1d7dd6362a60dee
Showing with 11 additions and 0 deletions.
  1. +11 −0 lib/net/scp.rb
View
@@ -107,6 +107,8 @@ def read_directive_state(channel)
channel[:times] = nil
channel[:remaining] = channel[:file][:size]
channel[:state] = :read_data
+
+ progress_callback(channel, channel[:file][:name], 0, channel[:file][:size])
when :end
channel[:local] = File.dirname(channel[:local])
channel[:state] = :finish if channel[:stack].empty?
@@ -124,6 +126,7 @@ def read_data_state(channel)
data = channel[:buffer].read!(channel[:remaining])
channel[:io].write(data)
channel[:remaining] -= data.length
+ progress_callback(channel, channel[:file][:name], channel[:file][:size] - channel[:remaining], channel[:file][:size])
await_response(channel, :finish_read) if channel[:remaining] == 0
end
@@ -206,6 +209,8 @@ def upload_file_state(channel)
directive = "C%04o %d %s\n" % [mode, channel[:stat].size, File.basename(channel[:current])]
channel.send_data(directive)
channel[:io] = File.open(channel[:current], "rb")
+ channel[:sent] = 0
+ progress_callback(channel, channel[:current], channel[:sent], channel[:stat].size)
await_response(channel, :send_data)
end
end
@@ -232,6 +237,8 @@ def send_data_state(channel)
channel.send_data("\0")
await_response(channel, :next_item)
else
+ channel[:sent] += data.length
+ progress_callback(channel, channel[:current], channel[:sent], channel[:stat].size)
channel.send_data(data)
end
end
@@ -254,6 +261,10 @@ def parse_directive(text)
else raise ArgumentError, "unknown directive: #{text.inspect}"
end
end
+
+ def progress_callback(channel, name, sent, total)
+ channel[:callback].call(name, sent, total) if channel[:callback]
+ end
end
end

0 comments on commit bbfca3b

Please sign in to comment.