Sha256: 74598f74583160c7d4ff3ef1ca894d356fe0a9e62e21fbd6cff5ad38987cc7e7

Contents?: true

Size: 830 Bytes

Versions: 2

Compression:

Stored size: 830 Bytes

Contents

require 'tempfile'
require 'clam_chowder'
require 'clam_chowder/backend'
require 'clam_chowder/response'

module ClamChowder
  class Scanner
    def self.infected_stream?(io)
      ::ClamChowder.infected_stream?(io) # XXX compatibility
    end

    def initialize(backend = ClamChowder.default_backend)
      @backend ||= ClamChowder::Backend.lookup(backend).new
    end

    def scan_io(readable)
      begin
        Tempfile.open('clam_chowder_temp', encoding: 'BINARY') do |file|
          while bytes = readable.read(1024 * 32)
            file.write(bytes.strip)
          end
          file.rewind
          file.chmod(0644)
          @backend.scan_file(file.path)
        end
      rescue => e
        raise ScanException.new(e)
      end
    ensure
      readable.rewind if readable.respond_to?(:rewind)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
clam_chowder-0.0.2 lib/clam_chowder/scanner.rb
clam_chowder-0.0.1 lib/clam_chowder/scanner.rb