Class: ClamAV::Commands::InstreamCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/clamav/commands/instream_command.rb

Instance Method Summary collapse

Constructor Details

#initialize(io, max_chunk_size = 1024) ⇒ InstreamCommand

Returns a new instance of InstreamCommand.



23
24
25
26
# File 'lib/clamav/commands/instream_command.rb', line 23

def initialize(io, max_chunk_size = 1024)
  @io = begin io rescue raise ArgumentError, 'io is required', caller; end
  @max_chunk_size = max_chunk_size
end

Instance Method Details

#call(conn) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/clamav/commands/instream_command.rb', line 28

def call(conn)
  conn.write_request("INSTREAM")

  while(packet = @io.read(@max_chunk_size))
    packet_size = [packet.size].pack("N")
    conn.raw_write("#{packet_size}#{packet}")
  end
  conn.raw_write("\x00\x00\x00\x00")
  get_status_from_response(conn.read_response)
end