bencode 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/bencode.rb +6 -10
  2. metadata +2 -4
data/lib/bencode.rb CHANGED
@@ -5,14 +5,10 @@
5
5
  #
6
6
  # == Synopsis
7
7
  #
8
- # "foobar".bencode #=> "6:foobar"
9
- # 42.bencode #=> "i42e"
10
- # [1, 2, 3].bencode #=> "li1ei2ei3ee"
11
- #
12
8
  # Bencoding (pronounced _bee-encode_) is a simple protocol, consiting of
13
9
  # only 4 value types.
14
10
  #
15
- # === Integers ===
11
+ # === Integers
16
12
  #
17
13
  # An integer is encoded an _i_ followed by the numeral itself, followed
18
14
  # by an _e_. Leading zeros are not allowed. Negative values are prefixed
@@ -22,7 +18,7 @@
22
18
  # -2.bencode #=> "i-2e"
23
19
  # 0.bencode #=> "i0e"
24
20
  #
25
- # === Strings ===
21
+ # === Strings
26
22
  #
27
23
  # Strings are a sequence of zero or more bytes. It is encoded as
28
24
  # _<length>:<contents>_, where _length_ is the lenth of _contents_. _length_
@@ -31,14 +27,14 @@
31
27
  # "".bencode #=> "0:"
32
28
  # "foo".bencode #=> "3:foo"
33
29
  #
34
- # === Lists ===
30
+ # === Lists
35
31
  #
36
32
  # Lists are encoded as _l_ followed by the elements, followed by _e_.
37
33
  # There is no element seperator.
38
34
  #
39
35
  # [1, 2, 3].bencode #=> "li1ei2ei3ee"
40
36
  #
41
- # === Dictionaries ===
37
+ # === Dictionaries
42
38
  #
43
39
  # Dictionaries are encoded as _d<contents>e_, where _contents_ is a sequence
44
40
  # of keys and values. Each value is immediately preceded by a key. Keys must
@@ -56,6 +52,7 @@
56
52
  #
57
53
  # * Daniel Martin
58
54
  # * Phrogz
55
+ # * Julien Pervillé
59
56
  #
60
57
  # == Copyright
61
58
  #
@@ -138,8 +135,7 @@ class Hash
138
135
  # All keys must be strings. The keys of the bencoded hash will
139
136
  # be in lexicographical order.
140
137
  def bencode
141
- pairs = map{|key, val| [key.to_str.bencode, val.bencode] }
142
- pairs.sort!{|a, b| a.first <=> b.first }
138
+ pairs = sort.map{|key, val| [key.to_str.bencode, val.bencode]}
143
139
  "d#{pairs.join('')}e"
144
140
  end
145
141
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: bencode
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.3.0
7
- date: 2006-09-29 00:00:00 +02:00
6
+ version: 0.3.1
7
+ date: 2006-10-24 00:00:00 +02:00
8
8
  summary: A Ruby implementation of the Bencode encoding used by BitTorrent
9
9
  require_paths:
10
10
  - lib
@@ -30,8 +30,6 @@ authors:
30
30
  - Daniel Schierbeck
31
31
  files:
32
32
  - lib/bencode.rb
33
- - test/tc_bencode.rb
34
- - test/tc_bdecode.rb
35
33
  test_files:
36
34
  - test/tc_bencode.rb
37
35
  - test/tc_bdecode.rb