bencode_blatyo 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +13 -5
- data/Rakefile +2 -2
- data/VERSION +1 -1
- data/bencode_blatyo.gemspec +5 -4
- data/lib/bencode.rb +6 -6
- data/lib/bencode/dictionary.rb +2 -2
- data/lib/bencode/integer.rb +2 -2
- data/lib/bencode/list.rb +2 -2
- data/lib/bencode/parser.rb +6 -6
- data/lib/bencode/string.rb +2 -2
- data/spec/bencode_spec.rb +15 -1
- data/spec/samples/python.torrent +0 -0
- metadata +5 -4
data/README.rdoc
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
= BEncode
|
1
|
+
= BEncode
|
2
2
|
* *Author* Allen Madsen (blatyo)
|
3
3
|
* *My* *Site* http://www.allenmadsen.com
|
4
4
|
* *Gem* http://gemcutter.org/gems/bencode_blatyo
|
5
5
|
* *Source* http://github.com/blatyo/bencode
|
6
6
|
* *Documentation* http://blatyo.github.com/bencode
|
7
|
+
* *Issue* *Tracker* http://github.com/blatyo/bencode/issues
|
7
8
|
|
8
9
|
== Synopsis
|
9
10
|
This gem provides a way to encode and parse bencodings used by the Bit Torrent protocol.
|
@@ -12,11 +13,11 @@ This gem provides a way to encode and parse bencodings used by the Bit Torrent p
|
|
12
13
|
|
13
14
|
# install the gem
|
14
15
|
> gem install bencode_blatyo
|
15
|
-
Successfully installed bencode_blatyo
|
16
|
+
Successfully installed bencode_blatyo
|
16
17
|
1 gem installed
|
17
|
-
Installing ri documentation for bencode_blatyo
|
18
|
-
Building YARD (yri) index for bencode_blatyo
|
19
|
-
Installing RDoc documentation for bencode_blatyo
|
18
|
+
Installing ri documentation for bencode_blatyo...
|
19
|
+
Building YARD (yri) index for bencode_blatyo...
|
20
|
+
Installing RDoc documentation for bencode_blatyo
|
20
21
|
|
21
22
|
# somefile.rb
|
22
23
|
require 'bencode'
|
@@ -124,6 +125,13 @@ of the last type registered for.
|
|
124
125
|
BEncode::Dictionary.register MyClass
|
125
126
|
MyClass.new.bencode #=> "d1:a1:a1:b1:be"
|
126
127
|
|
128
|
+
== Note on Reporting Issues
|
129
|
+
|
130
|
+
* Try to make a failing test case
|
131
|
+
* Tell me which version of ruby you're using
|
132
|
+
* Tell me which OS you are using
|
133
|
+
* Provide me with any extra files if necessary
|
134
|
+
|
127
135
|
== Note on Patches/Pull Requests
|
128
136
|
|
129
137
|
* Fork the project.
|
data/Rakefile
CHANGED
@@ -5,8 +5,8 @@ begin
|
|
5
5
|
require 'jeweler'
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
7
|
gem.name = "bencode_blatyo"
|
8
|
-
gem.summary = "This gem
|
9
|
-
gem.description = "This gem
|
8
|
+
gem.summary = "This gem has been renamed to bencodr. Use that one instead."
|
9
|
+
gem.description = "This gem has been renamed to bencodr. Use that one instead."
|
10
10
|
gem.email = "blatyo@gmail.com"
|
11
11
|
gem.homepage = "http://github.com/blatyo/bencode"
|
12
12
|
gem.authors = ["Allen Madsen"]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.1
|
data/bencode_blatyo.gemspec
CHANGED
@@ -5,12 +5,12 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{bencode_blatyo}
|
8
|
-
s.version = "1.0.
|
8
|
+
s.version = "1.0.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Allen Madsen"]
|
12
|
-
s.date = %q{2010-
|
13
|
-
s.description = %q{This gem
|
12
|
+
s.date = %q{2010-02-02}
|
13
|
+
s.description = %q{This gem has been renamed to bencodr. Use that one instead.}
|
14
14
|
s.email = %q{blatyo@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
@@ -40,6 +40,7 @@ Gem::Specification.new do |s|
|
|
40
40
|
"spec/bencode_spec.rb",
|
41
41
|
"spec/samples/bencode.rb.torrent",
|
42
42
|
"spec/samples/mini.bencode",
|
43
|
+
"spec/samples/python.torrent",
|
43
44
|
"spec/spec.opts",
|
44
45
|
"spec/spec_helper.rb"
|
45
46
|
]
|
@@ -47,7 +48,7 @@ Gem::Specification.new do |s|
|
|
47
48
|
s.rdoc_options = ["--charset=UTF-8"]
|
48
49
|
s.require_paths = ["lib"]
|
49
50
|
s.rubygems_version = %q{1.3.5}
|
50
|
-
s.summary = %q{This gem
|
51
|
+
s.summary = %q{This gem has been renamed to bencodr. Use that one instead.}
|
51
52
|
s.test_files = [
|
52
53
|
"spec/bencode/dictionary_spec.rb",
|
53
54
|
"spec/bencode/integer_spec.rb",
|
data/lib/bencode.rb
CHANGED
@@ -16,8 +16,8 @@ module BEncode
|
|
16
16
|
#
|
17
17
|
# BEncode.decode("6:string") #=> "string"
|
18
18
|
#
|
19
|
-
# @param [String] string the bencoded string to decode
|
20
|
-
# @return [String, Integer, Hash, Array] the decoded object
|
19
|
+
# @param [::String] string the bencoded string to decode
|
20
|
+
# @return [::String, ::Integer, ::Hash, ::Array] the decoded object
|
21
21
|
def decode(string)
|
22
22
|
scanner = StringScanner.new(string)
|
23
23
|
Parser.parse_object(scanner) or raise BEncodeError, "Invalid bencoding"
|
@@ -27,8 +27,8 @@ module BEncode
|
|
27
27
|
#
|
28
28
|
# BEncode.decode_file("simple.torrent") #=> "d8:announce32:http://www..."
|
29
29
|
#
|
30
|
-
# @param [String] file the file to decode
|
31
|
-
# @return [String, Integer, Hash, Array] the decoded object
|
30
|
+
# @param [::String] file the file to decode
|
31
|
+
# @return [::String, ::Integer, ::Hash, ::Array] the decoded object
|
32
32
|
def decode_file(file)
|
33
33
|
decode(File.open(file, 'rb') {|f| f.read})
|
34
34
|
end
|
@@ -38,7 +38,7 @@ module BEncode
|
|
38
38
|
# BEncode.encode("string") #=> "6:string"
|
39
39
|
#
|
40
40
|
# @param [#bencode] object the object to encode
|
41
|
-
# @return [String] the bencoded object
|
41
|
+
# @return [::String] the bencoded object
|
42
42
|
def encode(object)
|
43
43
|
object.bencode
|
44
44
|
end
|
@@ -47,7 +47,7 @@ module BEncode
|
|
47
47
|
#
|
48
48
|
# BEncode.encode("string") #=> "6:string"
|
49
49
|
#
|
50
|
-
# @param [String] file the file to write the bencoded object to
|
50
|
+
# @param [::String] file the file to write the bencoded object to
|
51
51
|
# @param [#bencode] object the object to encode
|
52
52
|
def encode_file(file, object)
|
53
53
|
File.open(file, 'wb') {|f| f.write encode(object)}
|
data/lib/bencode/dictionary.rb
CHANGED
@@ -10,7 +10,7 @@ module BEncode
|
|
10
10
|
#
|
11
11
|
# {:cow => "moo", :seven => 7}.bencode #=> "d3:cow3:moo5:seveni7ee"
|
12
12
|
#
|
13
|
-
# @return [String] the bencoded dictionary
|
13
|
+
# @return [::String] the bencoded dictionary
|
14
14
|
def bencode
|
15
15
|
(respond_to?(:to_h) ? to_h : to_hash).bencode
|
16
16
|
end
|
@@ -43,7 +43,7 @@ module BEncode
|
|
43
43
|
#
|
44
44
|
# {:cow => "moo", :seven => 7}.bencode #=> "d3:cow3:moo5:seveni7ee"
|
45
45
|
#
|
46
|
-
# @return [String] the bencoded dictionary
|
46
|
+
# @return [::String] the bencoded dictionary
|
47
47
|
def bencode
|
48
48
|
keys.sort{|a, b| a.to_s <=> b.to_s}.collect do |key|
|
49
49
|
key.to_s.bencode + self[key].bencode
|
data/lib/bencode/integer.rb
CHANGED
@@ -9,7 +9,7 @@ module BEncode
|
|
9
9
|
#
|
10
10
|
# 1.bencode #=> "i1e"
|
11
11
|
#
|
12
|
-
# @return [String] the bencoded integer
|
12
|
+
# @return [::String] the bencoded integer
|
13
13
|
def bencode
|
14
14
|
(respond_to?(:to_i) ? to_i : to_int).bencode
|
15
15
|
end
|
@@ -45,7 +45,7 @@ module BEncode
|
|
45
45
|
# 3.bencode #=> "i3e"
|
46
46
|
# -3.bencode #=> "i-3e"
|
47
47
|
#
|
48
|
-
# @return [String] the bencoded integer
|
48
|
+
# @return [::String] the bencoded integer
|
49
49
|
def bencode
|
50
50
|
[:i, self, :e].join
|
51
51
|
end
|
data/lib/bencode/list.rb
CHANGED
@@ -9,7 +9,7 @@ module BEncode
|
|
9
9
|
#
|
10
10
|
# [].bencode #=> "le"
|
11
11
|
#
|
12
|
-
# @return [String] the bencoded list
|
12
|
+
# @return [::String] the bencoded list
|
13
13
|
def bencode
|
14
14
|
(respond_to?(:to_ary) ? to_ary : to_a).bencode
|
15
15
|
end
|
@@ -41,7 +41,7 @@ module BEncode
|
|
41
41
|
#
|
42
42
|
# [:eggs, "ham", 3, 4.1].bencode #=> "l4:eggs3:hami3ei4ee"
|
43
43
|
#
|
44
|
-
# @return [String] the bencoded list
|
44
|
+
# @return [::String] the bencoded list
|
45
45
|
def bencode
|
46
46
|
collect do |element|
|
47
47
|
element.bencode
|
data/lib/bencode/parser.rb
CHANGED
@@ -11,7 +11,7 @@ module BEncode
|
|
11
11
|
# BEncode::Parser.parse_object(scanner) #=> "string"
|
12
12
|
#
|
13
13
|
# @param [StringScanner] scanner the scanner of a bencoded object
|
14
|
-
# @return [String, Integer, Hash, Array, nil] an object if type is recognized or nil
|
14
|
+
# @return [::String, ::Integer, ::Hash, ::Array, nil] an object if type is recognized or nil
|
15
15
|
def parse_object(scanner)
|
16
16
|
case scanner.peek(1)[0]
|
17
17
|
when ?0..?9
|
@@ -33,11 +33,11 @@ module BEncode
|
|
33
33
|
# BEncode::Parser.parse_string(scanner) #=> "string"
|
34
34
|
#
|
35
35
|
# @param [StringScanner] scanner the scanner of a bencoded string
|
36
|
-
# @return [String] the parsed string
|
36
|
+
# @return [::String] the parsed string
|
37
37
|
def parse_string(scanner)
|
38
38
|
length = scanner.scan(/[1-9][0-9]*|0/) or raise BEncodeError, "Invalid string: length invalid. #{scanner.pos}"
|
39
39
|
scanner.scan(/:/) or raise BEncodeError, "Invalid string: missing colon(:). #{scanner.pos}"
|
40
|
-
scanner.scan(/.{#{length
|
40
|
+
scanner.scan(/.{#{length}}/m) or raise BEncodeError, "Invalid string: length too long(#{length}) #{scanner.pos}."
|
41
41
|
end
|
42
42
|
|
43
43
|
# This method parases a bencoded integer.
|
@@ -46,7 +46,7 @@ module BEncode
|
|
46
46
|
# BEncode::Parser.parse_integer(scanner) #=> 1
|
47
47
|
#
|
48
48
|
# @param [StringScanner] scanner the scanner of a bencoded integer
|
49
|
-
# @return [Integer] the parsed integer
|
49
|
+
# @return [::Integer] the parsed integer
|
50
50
|
def parse_integer(scanner)
|
51
51
|
scanner.scan(/i/) or raise BEncodeError, "Invalid integer: missing opening i. #{scanner.pos}"
|
52
52
|
integer = scanner.scan(/-?[1-9][0-9]*|0/) or raise BEncodeError, "Invalid integer: valid integer not found. #{scanner.pos}"
|
@@ -60,7 +60,7 @@ module BEncode
|
|
60
60
|
# BEncode::Parser.parse_list(scanner) #=> []
|
61
61
|
#
|
62
62
|
# @param [StringScanner] scanner the scanner of a bencoded list
|
63
|
-
# @return [Array] the parsed array
|
63
|
+
# @return [::Array] the parsed array
|
64
64
|
def parse_list(scanner)
|
65
65
|
list = []
|
66
66
|
|
@@ -81,7 +81,7 @@ module BEncode
|
|
81
81
|
# BEncode::Parser.parse_dictionary(scanner) #=> {}
|
82
82
|
#
|
83
83
|
# @param [StringScanner] scanner the scanner of a bencoded dictionary
|
84
|
-
# @return [Hash] the parsed hash
|
84
|
+
# @return [::Hash] the parsed hash
|
85
85
|
def parse_dictionary(scanner)
|
86
86
|
dictionary = {}
|
87
87
|
|
data/lib/bencode/string.rb
CHANGED
@@ -11,7 +11,7 @@ module BEncode
|
|
11
11
|
#
|
12
12
|
# :symbol.bencode #=> "6:symbol"
|
13
13
|
#
|
14
|
-
# @return [String] the bencoded string
|
14
|
+
# @return [::String] the bencoded string
|
15
15
|
def bencode
|
16
16
|
(respond_to?(:to_s) ? to_s : to_str).bencode
|
17
17
|
end
|
@@ -46,7 +46,7 @@ module BEncode
|
|
46
46
|
#
|
47
47
|
# "string".bencode #=> "6:string"
|
48
48
|
#
|
49
|
-
# @return [String] the bencoded string
|
49
|
+
# @return [::String] the bencoded string
|
50
50
|
def bencode
|
51
51
|
[length, ':', self].join
|
52
52
|
end
|
data/spec/bencode_spec.rb
CHANGED
@@ -43,8 +43,13 @@ describe BEncode do
|
|
43
43
|
|
44
44
|
describe "#encode_file" do
|
45
45
|
context "when an object gets bencoded and written to a file" do
|
46
|
+
before :all do
|
47
|
+
@path = File.join(File.dirname(__FILE__), '..', 'tmp')
|
48
|
+
Dir.mkdir(@path) unless File.exists? @path
|
49
|
+
end
|
50
|
+
|
46
51
|
before :each do
|
47
|
-
@file = File.join(
|
52
|
+
@file = File.join(@path, 'test.bencode')
|
48
53
|
@object = "string"
|
49
54
|
BEncode.encode_file(@file, @object)
|
50
55
|
end
|
@@ -60,6 +65,15 @@ describe BEncode do
|
|
60
65
|
after :each do
|
61
66
|
File.delete(@file)
|
62
67
|
end
|
68
|
+
|
69
|
+
after :all do
|
70
|
+
Dir.delete(@path) if File.exists? @path
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should read a torrent with newlines as part of a string without raising an error" do
|
75
|
+
file = File.join(File.dirname(__FILE__), 'samples', 'python.torrent')
|
76
|
+
lambda{BEncode.decode_file file}.should_not raise_error
|
63
77
|
end
|
64
78
|
end
|
65
79
|
|
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bencode_blatyo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Allen Madsen
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-02-02 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: "0"
|
34
34
|
version:
|
35
|
-
description: This gem
|
35
|
+
description: This gem has been renamed to bencodr. Use that one instead.
|
36
36
|
email: blatyo@gmail.com
|
37
37
|
executables: []
|
38
38
|
|
@@ -65,6 +65,7 @@ files:
|
|
65
65
|
- spec/bencode_spec.rb
|
66
66
|
- spec/samples/bencode.rb.torrent
|
67
67
|
- spec/samples/mini.bencode
|
68
|
+
- spec/samples/python.torrent
|
68
69
|
- spec/spec.opts
|
69
70
|
- spec/spec_helper.rb
|
70
71
|
has_rdoc: true
|
@@ -94,7 +95,7 @@ rubyforge_project:
|
|
94
95
|
rubygems_version: 1.3.5
|
95
96
|
signing_key:
|
96
97
|
specification_version: 3
|
97
|
-
summary: This gem
|
98
|
+
summary: This gem has been renamed to bencodr. Use that one instead.
|
98
99
|
test_files:
|
99
100
|
- spec/bencode/dictionary_spec.rb
|
100
101
|
- spec/bencode/integer_spec.rb
|