Class: Download

Inherits:
Transfer show all
Defined in:
lib/vendor/xmpp4r/data/doc/xmpp4r/examples/advanced/fileserve.rb

Instance Attribute Summary

Attributes inherited from Transfer

#bytes, #filename, #filesize, #peer

Instance Method Summary collapse

Methods inherited from Transfer

#done?, #say, #stats, #stats_loop, #transfer

Constructor Details

#initialize(filetransfer, peer, filename, msgblock, socksconf) ⇒ Download

Returns a new instance of Download.



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/vendor/xmpp4r/data/doc/xmpp4r/examples/advanced/fileserve.rb', line 139

def initialize(filetransfer, peer, filename, msgblock, socksconf)
  begin
    filesize = File.size(filename)
  rescue
    filesize = 0
  end

  super(filetransfer, peer, filename, filesize, msgblock)

  Thread.new {
    begin
      raise "No regular file" unless File.file?(filename)

      source = Jabber::FileTransfer::FileSource.new(filename)
      stream = filetransfer.offer(peer, source)
      unless stream
        raise "Well, you should accept what you request..."
        @done = true
      end

      if stream.kind_of?(Jabber::Bytestreams::SOCKS5Bytestreams)
        socksconf.call(stream)
        stream.add_streamhost_callback(nil, nil, &@streamhost_cb)
      end

      stream.open
      transfer(source, stream)
      stream.close
      @done = true
    rescue
      say "Error: #{$!}"
      @done = true
    end
  }
end