class Jabber::FileTransfer::FileSource
Simple implementation of TransferSource for sending simple files (supports ranged transfers)
Public Class Methods
new(filename)
click to toggle source
# File lib/xmpp4r/bytestreams/helper/filetransfer.rb, line 70 def initialize(filename) @file = File.new(filename) @filename = filename @bytes_read = 0 @length = nil end
Public Instance Methods
can_range?()
click to toggle source
# File lib/xmpp4r/bytestreams/helper/filetransfer.rb, line 118 def can_range? true end
date()
click to toggle source
# File lib/xmpp4r/bytestreams/helper/filetransfer.rb, line 91 def date @file.mtime end
filename()
click to toggle source
# File lib/xmpp4r/bytestreams/helper/filetransfer.rb, line 77 def filename File::basename @filename end
length=(l)
click to toggle source
# File lib/xmpp4r/bytestreams/helper/filetransfer.rb, line 114 def length=(l) @length = l end
mime()
click to toggle source
Everything is 'application/octet-stream'
# File lib/xmpp4r/bytestreams/helper/filetransfer.rb, line 83 def mime 'application/octet-stream' end
read(length=512)
click to toggle source
Because it can_range?, this method implements length checking
# File lib/xmpp4r/bytestreams/helper/filetransfer.rb, line 97 def read(length=512) if @length return nil if @bytes_read >= @length # Already read everything requested if @bytes_read + length > @length # Will we read more than requested? length = @length - @bytes_read # Truncate it! end end buf = @file.read(length) @bytes_read += buf.size if buf buf end
seek(position)
click to toggle source
# File lib/xmpp4r/bytestreams/helper/filetransfer.rb, line 110 def seek(position) @file.seek(position) end
size()
click to toggle source
# File lib/xmpp4r/bytestreams/helper/filetransfer.rb, line 87 def size File.size @filename end