Class: Jabber::FileTransfer::FileSource
- Inherits:
-
Object
- Object
- Jabber::FileTransfer::FileSource
- Includes:
- TransferSource
- Defined in:
- lib/xmpp4r/bytestreams/helper/filetransfer.rb
Overview
Simple implementation of TransferSource for sending simple files (supports ranged transfers)
Instance Method Summary collapse
- #can_range? ⇒ Boolean
- #date ⇒ Object
- #filename ⇒ Object
-
#initialize(filename) ⇒ FileSource
constructor
A new instance of FileSource.
- #length=(l) ⇒ Object
-
#mime ⇒ Object
Everything is ‘application/octet-stream’.
-
#read(length = 512) ⇒ Object
Because it can_range?, this method implements length checking.
- #seek(position) ⇒ Object
- #size ⇒ Object
Methods included from TransferSource
Constructor Details
#initialize(filename) ⇒ FileSource
Returns a new instance of FileSource.
72 73 74 75 76 77 |
# File 'lib/xmpp4r/bytestreams/helper/filetransfer.rb', line 72 def initialize(filename) @file = File.new(filename) @filename = filename @bytes_read = 0 @length = nil end |
Instance Method Details
#can_range? ⇒ Boolean
120 121 122 |
# File 'lib/xmpp4r/bytestreams/helper/filetransfer.rb', line 120 def can_range? true end |
#date ⇒ Object
93 94 95 |
# File 'lib/xmpp4r/bytestreams/helper/filetransfer.rb', line 93 def date @file.mtime end |
#filename ⇒ Object
79 80 81 |
# File 'lib/xmpp4r/bytestreams/helper/filetransfer.rb', line 79 def filename File::basename @filename end |
#length=(l) ⇒ Object
116 117 118 |
# File 'lib/xmpp4r/bytestreams/helper/filetransfer.rb', line 116 def length=(l) @length = l end |
#mime ⇒ Object
Everything is ‘application/octet-stream’
85 86 87 |
# File 'lib/xmpp4r/bytestreams/helper/filetransfer.rb', line 85 def mime 'application/octet-stream' end |
#read(length = 512) ⇒ Object
Because it can_range?, this method implements length checking
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/xmpp4r/bytestreams/helper/filetransfer.rb', line 99 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) ⇒ Object
112 113 114 |
# File 'lib/xmpp4r/bytestreams/helper/filetransfer.rb', line 112 def seek(position) @file.seek(position) end |
#size ⇒ Object
89 90 91 |
# File 'lib/xmpp4r/bytestreams/helper/filetransfer.rb', line 89 def size File.size @filename end |