Class: Jabber::FileTransfer::FileSource

Class | Jabber::FileTransfer::FileSource
In: | lib/xmpp4r/bytestreams/helper/filetransfer.rb
Parent: | Object

Simple implementation of TransferSource for sending simple files (supports ranged transfers)

### Methods

can_range? date filename length= mime new read seek size

### Included Modules

TransferSource

### Public Class methods

new(filename)

[Source]

        # File lib/xmpp4r/bytestreams/helper/filetransfer.rb, line 70
    70:       def initialize(filename)
    71:         @file = File.new(filename)
    72:         @filename = filename
    73:         @bytes_read = 0
    74:         @length = nil
    75:       end

### Public Instance methods

can_range?()

[Source]

         # File lib/xmpp4r/bytestreams/helper/filetransfer.rb, line 118
    118:       def can_range?
    119:         true
    120:       end

date()

[Source]

        # File lib/xmpp4r/bytestreams/helper/filetransfer.rb, line 91
    91:       def date
    92:         @file.mtime
    93:       end

filename()

[Source]

        # File lib/xmpp4r/bytestreams/helper/filetransfer.rb, line 77
    77:       def filename
    78:         File::basename @filename
    79:       end

length=(l)

[Source]

         # File lib/xmpp4r/bytestreams/helper/filetransfer.rb, line 114
    114:       def length=(l)
    115:         @length = l
    116:       end

mime()

Everything is ‘application/octet-stream‘

[Source]

        # File lib/xmpp4r/bytestreams/helper/filetransfer.rb, line 83
    83:       def mime
    84:         'application/octet-stream'
    85:       end

read(length=512)

Because it can_range?, this method implements length checking

[Source]

         # File lib/xmpp4r/bytestreams/helper/filetransfer.rb, line 97
     97:       def read(length=512)
     98:         if @length
     99:           return nil if @bytes_read >= @length  # Already read everything requested
    100:           if @bytes_read + length > @length # Will we read more than requested?
    101:             length = @length - @bytes_read  # Truncate it!
    102:           end
    103:         end
    104:
    105:         buf = @file.read(length)
    106:         @bytes_read += buf.size if buf
    107:         buf
    108:       end

seek(position)

[Source]

         # File lib/xmpp4r/bytestreams/helper/filetransfer.rb, line 110
    110:       def seek(position)
    111:         @file.seek(position)
    112:       end

size()

[Source]

        # File lib/xmpp4r/bytestreams/helper/filetransfer.rb, line 87
    87:       def size
    88:         File.size @filename
    89:       end

[Validate]