Class: HrrRbSftp::Receiver

Inherits:
Object
  • Object
show all
Defined in:
lib/hrr_rb_sftp/receiver.rb

Overview

This class implements payload receiver.

Instance Method Summary collapse

Constructor Details

#initialize(io_in) ⇒ Receiver

Instantiates a new payload receiver for the input IO.

Parameters:

  • io_in (IO)

    An IO for input.



13
14
15
# File 'lib/hrr_rb_sftp/receiver.rb', line 13

def initialize io_in
  @io_in = io_in
end

Instance Method Details

#receiveString?

Receives payload_length payload. When input IO is EOF, returns nil.

Returns:

  • (String, nil)

    Received payload. when input IO is EOF, retruns nil.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/hrr_rb_sftp/receiver.rb', line 22

def receive
  begin
    paylaod_length = Protocol::Common::DataTypes::Uint32.decode(@io_in)
  rescue NoMethodError
    nil
  else
    payload = @io_in.read(paylaod_length)
    if payload.nil? || payload.bytesize != paylaod_length
      nil
    else
      payload
    end
  end
end