bencode 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/bencode.rb +31 -0
- metadata +3 -3
data/lib/bencode.rb
CHANGED
@@ -1,6 +1,34 @@
|
|
1
1
|
# Thanks to Daniel Martin and all the other lads at ruby-lang for
|
2
2
|
# helping me out.
|
3
3
|
|
4
|
+
# bencode is a Ruby implementation of the Bencode data serialization
|
5
|
+
# format used in the BitTorrent protocol.
|
6
|
+
#
|
7
|
+
# == Synopsis
|
8
|
+
#
|
9
|
+
# "foobar".bencode #=> "6:foobar"
|
10
|
+
# 42.bencode #=> "i42e"
|
11
|
+
# [1, 2, 3].bencode #=> "li1ei2ei3ee"
|
12
|
+
#
|
13
|
+
# == Authors
|
14
|
+
#
|
15
|
+
# * Daniel Schierbeck
|
16
|
+
#
|
17
|
+
# == Contributors
|
18
|
+
#
|
19
|
+
# * Daniel Martin
|
20
|
+
# * Phrogz
|
21
|
+
#
|
22
|
+
# == Copyright
|
23
|
+
#
|
24
|
+
# Bencode is free software; you can redistribute it and/or modify it under the
|
25
|
+
# terms of the GNU General Public License as published by the Free Software
|
26
|
+
# Foundation; either version 2 of the License, or (at your option) any later
|
27
|
+
# version.
|
28
|
+
#
|
29
|
+
# Bencode is distributed in the hope that it will be useful, but WITHOUT ANY
|
30
|
+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
31
|
+
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
4
32
|
|
5
33
|
class Object
|
6
34
|
# Raises an exception. Subclasses of Object must themselves
|
@@ -29,6 +57,7 @@ class String
|
|
29
57
|
#
|
30
58
|
# "foo".bencode #=> "3:foo"
|
31
59
|
# "".bencode #=> "0:"
|
60
|
+
#
|
32
61
|
def bencode
|
33
62
|
"#{length}:#{self}"
|
34
63
|
end
|
@@ -37,6 +66,7 @@ class String
|
|
37
66
|
# through bencoding.
|
38
67
|
#
|
39
68
|
# "li1ei2ei3ee".bdecode #=> [1, 2, 3]
|
69
|
+
#
|
40
70
|
def bdecode
|
41
71
|
Bencode.load(self)
|
42
72
|
end
|
@@ -56,6 +86,7 @@ class Array
|
|
56
86
|
# +lxe+, where x is zero or more bencoded objects.
|
57
87
|
#
|
58
88
|
# [1, "foo"].bencode #=> "li1e3:fooe"
|
89
|
+
#
|
59
90
|
def bencode
|
60
91
|
"l#{map{|obj| obj.bencode}.join('') }e"
|
61
92
|
end
|
metadata
CHANGED
@@ -3,13 +3,13 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: bencode
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0
|
6
|
+
version: 0.1.0
|
7
7
|
date: 2006-09-17 00:00:00 +02:00
|
8
|
-
summary:
|
8
|
+
summary: Serialize and unserialize data to and from the Bencode format
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
11
|
email:
|
12
|
-
homepage:
|
12
|
+
homepage: bencode.rubyforge.org
|
13
13
|
rubyforge_project: bencode
|
14
14
|
description:
|
15
15
|
autorequire: bencode
|