Implements the read operation, which reads data from an open file handle. This also implements the common case of reading to the end of the file. In that case, the callback is guaranteed to receive the contents of the entire file in one chunk.

Methods
Constants
CHUNK_SIZE = 64 * 1024
  The maximum amount of data to read at once when reading an entire file. (Setting this to a larger value may cause problems, especially with very large files, so beware!)
Public Instance methods
do_data( data )

Invoked when a data packet is received from the server. If the original request was for an entire file, this will send another read request, offset to the end of the data that has been read so far. Otherwise, the callback will be invoked directly.

    # File lib/net/sftp/operations/read.rb, line 49
49:     def do_data( data )
50:       @log.debug "[#{@id}] got #{data.length} bytes" if @log.debug?
51: 
52:       @data << data
53:       if @length < 0 || @data.length < @length
54:         if @length < 0
55:           length = CHUNK_SIZE
56:         else
57:           length = @length - @data.length
58:           length = length > CHUNK_SIZE ? CHUNK_SIZE : length
59:         end
60: 
61:         @log.debug "[#{@id}] requesting #{length} more bytes" if @log.debug?
62:         @driver.read @id, @handle, @offset + @data.length, length
63:         @session.register( @id, self )
64:       else
65:         @callback[ OK, @data ]
66:       end
67:     end
do_status( code, message, language )

Invoked when a status code is received from the server. If the code is FX_EOF, then no data could be read because the end of the file was reached. In this case, the callback is invoked with the data that has been read so far. Other status codes are handled by the superclass.

    # File lib/net/sftp/operations/read.rb, line 73
73:     def do_status( code, message, language )
74:       if code == FX_EOF
75:         @log.debug "[#{@id}] got EOF" if @log.debug?
76:         @callback[ OK, @data ]
77:       else
78:         super
79:       end
80:     end
perform( handle, offset=0, length=-1 )

Perform the operation. If length is less than 0 (the default), then the entire file (from the given offset) will be read and returned in "one fell swoop". Otherwise, the given length of data will be requested.

    # File lib/net/sftp/operations/read.rb, line 35
35:     def perform( handle, offset=0, length=-1 )
36:       @length = length
37:       @handle = handle
38:       @offset = offset
39:       @data = ""
40: 
41:       real_length = ( length < 0 ? CHUNK_SIZE : length )
42:       @driver.read( nil, handle, offset, real_length )
43:     end