Class: Mu::Xtractr::Stream

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/mu/xtractr/stream.rb,
lib/mu/xtractr/stream/http.rb,
lib/mu/xtractr/test/tc_stream.rb,
lib/mu/xtractr/test/stream/tc_http.rb

Overview

end

Defined Under Namespace

Classes: HTTP, Message, Processor, Test

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xtractr, flow, json) ⇒ Stream

:nodoc:



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/mu/xtractr/stream.rb', line 93

def initialize xtractr, flow, json # :nodoc:
    @xtractr  = xtractr
    @flow     = flow
    @messages = []
    @contents = []
    
    json['packets'].each do |pkt|
        bytes = (pkt['b'] || []).map { |b| b.chr }.join('')
        if messages.empty? or messages[-1].dir != pkt['d']
            messages << Message.new(self, messages.size, pkt['d'], '')
        end
        messages[-1].bytes << bytes
    end
    
    # Run the stream/messages through each registered processor to pull
    # out attachments, files, etc
    Processor.processors.each do |processor|
        if processor.matches? self
            processor.extract self
            break
        end
    end
end

Instance Attribute Details

#contentsObject (readonly)

Return a list of extracted content from the messages.



59
60
61
# File 'lib/mu/xtractr/stream.rb', line 59

def contents
  @contents
end

#flowObject (readonly)

Return the flow that this stream represents.



53
54
55
# File 'lib/mu/xtractr/stream.rb', line 53

def flow
  @flow
end

#messagesObject (readonly)

Return a list of Messages in this stream.



56
57
58
# File 'lib/mu/xtractr/stream.rb', line 56

def messages
  @messages
end

#xtractrObject (readonly)

:nodoc:



50
51
52
# File 'lib/mu/xtractr/stream.rb', line 50

def xtractr
  @xtractr
end

Instance Method Details

#each_message(&blk) ⇒ Object Also known as: each

Iterate over each message in this stream



118
119
120
121
# File 'lib/mu/xtractr/stream.rb', line 118

def each_message &blk
    messages.each(&blk)
    return self
end

#inspectObject

:nodoc:



123
124
125
# File 'lib/mu/xtractr/stream.rb', line 123

def inspect # :nodoc:
    return "#<stream:#{flow.id} ##{messages.size} messages>"
end