Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/rubytorrent/bencoding.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.bencoded?(c) ⇒ Boolean
161 162 163 |
# File 'lib/rubytorrent/bencoding.rb', line 161 def self.bencoded?(c) c == ?d end |
.parse_bencoding(c, s) ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/rubytorrent/bencoding.rb', line 165 def self.parse_bencoding(c, s) ret = {} key = nil RubyTorrent::BStream.new(s).each do |x| if key == nil key = x else ret[key] = x key = nil end end raise RubyTorrent::BEncodingError, "no dictionary terminator" unless s.getc == ?e ret end |
Instance Method Details
#to_bencoding ⇒ Object
150 151 152 153 154 155 156 157 158 159 |
# File 'lib/rubytorrent/bencoding.rb', line 150 def to_bencoding "d" + keys.sort.map do |k| v = self[k] if v.nil? nil else [k.to_bencoding, v.to_bencoding].join end end.compact.join + "e" end |