Module: Blather::FileTransfer::SimpleFileReceiver

Defined in:
lib/blather/file_transfer.rb

Overview

Simple handler for incoming file transfers

You can define your own handler and pass it to the accept method.

Instance Method Summary collapse

Instance Method Details

#initialize(path, size) ⇒ Object



83
84
85
86
87
# File 'lib/blather/file_transfer.rb', line 83

def initialize(path, size)
  @path = path
  @size = size
  @transferred = 0
end

#post_initObject



90
91
92
# File 'lib/blather/file_transfer.rb', line 90

def post_init
  @file = File.open(@path, "w")
end

#receive_data(data) ⇒ Object



95
96
97
98
# File 'lib/blather/file_transfer.rb', line 95

def receive_data(data)
  @transferred += data.size
  @file.write data
end

#unbindObject



101
102
103
104
# File 'lib/blather/file_transfer.rb', line 101

def unbind
  @file.close
  File.delete(@path) unless @transferred == @size
end