Class: RubyTorrent::BStream

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rubytorrent/bencoding.rb

Constant Summary collapse

@@classes =
[]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(s) ⇒ BStream

Returns a new instance of BStream.



29
30
31
# File 'lib/rubytorrent/bencoding.rb', line 29

def initialize(s)
  @s = s
end

Class Method Details

.register_bencoded_class(c) ⇒ Object



33
34
35
# File 'lib/rubytorrent/bencoding.rb', line 33

def self.register_bencoded_class(c)
  @@classes.push c
end

Instance Method Details

#eachObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rubytorrent/bencoding.rb', line 37

def each
  happy = true
  begin
    happy = false
    c = @s.getc
    @@classes.each do |klass|
      if klass.bencoded? c
        o = klass.parse_bencoding(c, @s)
        happy = true
        yield o
        break
      end
    end unless c.nil?
    unless happy
      @s.ungetc c unless c.nil?
    end
  end while happy
  self
end