bencode 0.8.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NzJhZTUzNzVhM2ZmMzNjOTJhYTkwNGJhOWU4NTFjZTNhOTdjY2Y1Ng==
5
- data.tar.gz: !binary |-
6
- YWQzMDg5NmM2ODYwY2M1Y2JhZTU4NzA0ZmE5MWRmN2QwODEwNTIxNA==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- MjM1ODBjMmNmMjU1YmY3ZGViNDZiMmE5OTlkZTg4NWZjZGFkZGQ0NzEyNmQ3
10
- NjEzOTI2NmVjMDEwNGYwNTI0NTAyNGU5YmE3ZWU5ODg4MWExMGJjZGY1MTll
11
- YmE2MzljNTg1YzYzYTdhYjljMGQzOWQxYWYwOWQ2NTllM2M1NGQ=
12
- data.tar.gz: !binary |-
13
- ZmQ4ODY3NDM3NDZiYThjZDc5MTYzOTNiOTdlOGRhMDJmNjhhNDAxY2Q2OTM2
14
- NWUwZmFhMWVkNGI0ZGI5ZWZlM2UzMTJmYWIxNDVmOWMzNzliY2RmMWUwMGVj
15
- YjdlMDVhN2YxYzQwZWFiNjA1ZDY2OTI1MmU2YTU3OTYwZWZjZjM=
2
+ SHA1:
3
+ metadata.gz: 07cb5be3744b878726ce641c469802ed586c800a
4
+ data.tar.gz: 1645e9613e22a9e144f4f766809821bf144ce891
5
+ SHA512:
6
+ metadata.gz: 59701813409b78eba18008e281fc7c0dbe817baabd2e47d2bef356af3d7f5c43bb8087ba9caefd0ff80e974f61249878021138bb58f46daa62a06fb0a97e073b
7
+ data.tar.gz: 13aa5d05f693c5386fd6d8500c6e8b76cad3459ed159a03ba60dece5d116d6eb680e53a071d24b303282d80f2965b9b75675168850f9d5cba49f0a077eabf3e9
data/Gemfile CHANGED
@@ -1,5 +1,3 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  gemspec
4
-
5
- gem "shoulda", :git => "git://github.com/dasch/shoulda.git", :branch => "minitest"
@@ -7,8 +7,8 @@ Gem::Specification.new do |s|
7
7
  ## If your rubyforge_project name is different, then edit it and comment out
8
8
  ## the sub! line in the Rakefile
9
9
  s.name = 'bencode'
10
- s.version = '0.8.0'
11
- s.date = '2013-03-15'
10
+ s.version = '0.8.1'
11
+ s.date = '2014-05-19'
12
12
 
13
13
  s.summary = "Encode and decode bencoded data"
14
14
  s.description = "A simple encoder and decoder for the BitTorrent serialization format."
@@ -16,6 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.authors = ["Daniel Schierbeck"]
17
17
  s.email = "daniel.schierbeck@gmail.com"
18
18
  s.homepage = "http://github.com/dasch/ruby-bencode"
19
+ s.license = 'MIT'
19
20
 
20
21
  s.require_paths = %w[lib]
21
22
 
@@ -41,9 +42,7 @@ Gem::Specification.new do |s|
41
42
  lib/bencode/core_ext/io.rb
42
43
  lib/bencode/core_ext/object.rb
43
44
  lib/bencode/core_ext/string.rb
44
- lib/bencode/core_ext/stringio.rb
45
45
  lib/bencode/decode.rb
46
- lib/bencode/parseio.rb
47
46
  lib/bencode/parser.rb
48
47
  test/benchmark/decoding.rb
49
48
  test/benchmark/encoding.rb
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # See {BEncode.load} and {BEncode.dump}.
5
5
  module BEncode
6
- VERSION = "0.8.0"
6
+ VERSION = "0.8.1"
7
7
 
8
8
  class DecodeError < StandardError
9
9
  end
@@ -9,7 +9,7 @@ class Hash
9
9
  def bencode
10
10
  pairs = sort.map{|key, val| [key.to_s.bencode, val.bencode] }
11
11
  "d#{pairs.join}e"
12
- rescue NoMethodError => error
12
+ rescue NoMethodError
13
13
  raise BEncode::EncodeError, "dictionary keys must be strings"
14
14
  end
15
15
  end
@@ -1,8 +1,4 @@
1
- require 'bencode/parseio'
2
-
3
- class IO
4
- include BEncode::ParseIO
5
-
1
+ class IO
6
2
  def self.bdecode(filename)
7
3
  open(filename, 'rb') {|io| io.bdecode}
8
4
  end
@@ -2,13 +2,23 @@
2
2
  class String
3
3
  #
4
4
  # Bencodes the String object. Bencoded strings are represented
5
- # as <code>x</code>:<code>y</code>, where +y+ is the string and +x+
5
+ # as <code>x</code>:<code>y</code>, where +y+ is the string and +x+
6
6
  # is the length of the string.
7
- #
7
+ #
8
8
  # "foo".bencode #=> "3:foo"
9
9
  # "".bencode #=> "0:"
10
10
  #
11
11
  def bencode
12
- "#{length}:#{self}"
12
+ "#{bytesize}:#{self}"
13
+ end
14
+
15
+ #
16
+ # Bdecodes the String object and returns the data serialized
17
+ # through bencoding.
18
+ #
19
+ # "li1ei2ei3ee".bdecode #=> [1, 2, 3]
20
+ #
21
+ def bdecode
22
+ BEncode.load(self)
13
23
  end
14
24
  end
@@ -22,7 +22,7 @@ module BEncode
22
22
  scanner = BEncode::Parser.new(str)
23
23
  obj = scanner.parse!
24
24
  raise BEncode::DecodeError unless (opts[:ignore_trailing_junk] || scanner.eos?)
25
- return obj
25
+ obj
26
26
  end
27
27
 
28
28
  # Decodes the file located at +path+.
@@ -34,15 +34,3 @@ module BEncode
34
34
  load(File.open(path, 'rb').read, opts)
35
35
  end
36
36
  end
37
-
38
- class String
39
- #
40
- # Bdecodes the String object and returns the data serialized
41
- # through bencoding.
42
- #
43
- # "li1ei2ei3ee".bdecode #=> [1, 2, 3]
44
- #
45
- def bdecode
46
- BEncode.load(self)
47
- end
48
- end
@@ -1,22 +1,22 @@
1
1
  require 'stringio'
2
- require 'bencode/parseio'
3
2
 
4
3
  module BEncode
5
4
  class Parser
6
5
  attr_reader :stream
7
6
 
8
7
  def initialize(stream)
9
- if stream.kind_of? BEncode::ParseIO
10
- @stream = stream
11
- elsif stream.respond_to? :string
12
- @stream = StringIO.new stream.string
13
- elsif stream.respond_to? :to_s
14
- @stream = StringIO.new stream.to_s
15
- end
8
+ @stream =
9
+ if stream.kind_of?(IO) || stream.kind_of?(StringIO)
10
+ stream
11
+ elsif stream.respond_to? :string
12
+ StringIO.new stream.string
13
+ elsif stream.respond_to? :to_s
14
+ StringIO.new stream.to_s
15
+ end
16
16
  end
17
17
 
18
18
  def parse!
19
- case stream.peek
19
+ case peek
20
20
  when ?i then parse_integer!
21
21
  when ?l then parse_list!
22
22
  when ?d then parse_dict!
@@ -39,7 +39,7 @@ module BEncode
39
39
  def parse_list!
40
40
  stream.getc
41
41
  ary = []
42
- ary.push(parse!) until stream.peek == ?e
42
+ ary.push(parse!) until peek == ?e
43
43
  stream.getc
44
44
  ary
45
45
  end
@@ -47,7 +47,7 @@ module BEncode
47
47
  def parse_dict!
48
48
  stream.getc
49
49
  hsh = {}
50
- until stream.peek == ?e
50
+ until peek == ?e
51
51
  key = parse!
52
52
 
53
53
  unless key.is_a? String or key.is_a? Fixnum
@@ -76,5 +76,11 @@ module BEncode
76
76
 
77
77
  str
78
78
  end
79
+
80
+ def peek
81
+ c = stream.getc
82
+ stream.ungetc(c)
83
+ c
84
+ end
79
85
  end
80
86
  end
@@ -1,7 +1,7 @@
1
1
  require 'environment'
2
2
 
3
- class BitTorrentTest < MiniTest::Unit::TestCase
4
- should "load a bencoded torrent file" do
3
+ describe "bittorrent" do
4
+ it "should load a bencoded torrent file" do
5
5
  BEncode.load_file("test/fixtures/python.torrent")
6
6
  pass
7
7
  end
@@ -1,19 +1,17 @@
1
1
  require 'environment'
2
2
 
3
- class DecodingTest < MiniTest::Unit::TestCase
4
- context "The BEncode decoder" do
5
- should_decode 42, "i42e"
6
- should_decode 0, "i0e"
7
- should_decode -42, "i-42e"
3
+ describe "decoding" do
4
+ it_should_decode 42, "i42e"
5
+ it_should_decode 0, "i0e"
6
+ it_should_decode -42, "i-42e"
8
7
 
9
- should_decode "foo", "3:foo"
10
- should_decode "", "0:"
8
+ it_should_decode "foo", "3:foo"
9
+ it_should_decode "", "0:"
11
10
 
12
- should_decode [1, 2, 3], "li1ei2ei3ee"
13
-
14
- hsh = {"foo" => "bar", "baz" => "qux"}
15
- should_decode hsh, "d3:foo3:bar3:baz3:quxe"
16
-
17
- should_decode 42, "i42eBOGUS", :ignore_trailing_junk => true
18
- end
11
+ it_should_decode [1, 2, 3], "li1ei2ei3ee"
12
+
13
+ hsh = {"foo" => "bar", "baz" => "qux"}
14
+ it_should_decode hsh, "d3:foo3:bar3:baz3:quxe"
15
+
16
+ it_should_decode 42, "i42eBOGUS", :ignore_trailing_junk => true
19
17
  end
@@ -1,8 +1,8 @@
1
+ # encoding: utf-8
1
2
  require 'environment'
2
3
 
3
- class EncodingTest < MiniTest::Unit::TestCase
4
- context "The BEncode encoder" do
5
- should_encode "i42e", 42
6
- should_encode "3:foo", "foo"
7
- end
4
+ describe "encoding" do
5
+ it_should_encode "i42e", 42
6
+ it_should_encode "3:foo", "foo"
7
+ it_should_encode "5:café", "café"
8
8
  end
@@ -1,11 +1,9 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
3
 
4
- require 'minitest/unit'
4
+ require 'minitest/autorun'
5
5
  require 'shoulda'
6
6
 
7
- MiniTest::Unit.autorun
8
-
9
7
  require File.dirname(__FILE__) + '/../lib/bencode'
10
8
  Dir.glob(File.dirname(__FILE__) + '/shoulda_macros/*.rb').each do |macro|
11
9
  require macro
@@ -1,7 +1,7 @@
1
1
 
2
- class MiniTest::Unit::TestCase
3
- def self.should_decode(expected, encoded, opts = {})
4
- should "decode #{encoded.inspect} into #{expected.inspect}" do
2
+ class MiniTest::Test
3
+ def self.it_should_decode(expected, encoded, opts = {})
4
+ it "should decode #{encoded.inspect} into #{expected.inspect}" do
5
5
  assert_equal expected, BEncode.load(encoded, opts)
6
6
  end
7
7
  end
@@ -1,7 +1,7 @@
1
1
 
2
- class MiniTest::Unit::TestCase
3
- def self.should_encode(expected, value)
4
- should "encode #{value.inspect} into #{expected.inspect}" do
2
+ class MiniTest::Test
3
+ def self.it_should_encode(expected, value)
4
+ it "should encode #{value.inspect} into #{expected.inspect}" do
5
5
  assert_equal expected, value.bencode
6
6
  end
7
7
  end
@@ -1,10 +1,8 @@
1
1
  require 'environment'
2
2
 
3
- class UTF8DecodingTest < MiniTest::Unit::TestCase
4
- context "The BEncode decoder" do
5
- should "be able to handle UTF8-encoded data" do
6
- BEncode.load_file('test/fixtures/test.torrent')
7
- pass
8
- end
3
+ describe "utf encoding" do
4
+ it "should be able to handle UTF8-encoded data" do
5
+ BEncode.load_file('test/fixtures/test.torrent')
6
+ pass
9
7
  end
10
8
  end
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bencode
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Schierbeck
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-15 00:00:00.000000000 Z
11
+ date: 2014-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: shoulda
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  description: A simple encoder and decoder for the BitTorrent serialization format.
@@ -86,9 +86,7 @@ files:
86
86
  - lib/bencode/core_ext/io.rb
87
87
  - lib/bencode/core_ext/object.rb
88
88
  - lib/bencode/core_ext/string.rb
89
- - lib/bencode/core_ext/stringio.rb
90
89
  - lib/bencode/decode.rb
91
- - lib/bencode/parseio.rb
92
90
  - lib/bencode/parser.rb
93
91
  - test/benchmark/decoding.rb
94
92
  - test/benchmark/encoding.rb
@@ -102,7 +100,8 @@ files:
102
100
  - test/shoulda_macros/encoding.rb
103
101
  - test/utf8_decoding_test.rb
104
102
  homepage: http://github.com/dasch/ruby-bencode
105
- licenses: []
103
+ licenses:
104
+ - MIT
106
105
  metadata: {}
107
106
  post_install_message:
108
107
  rdoc_options:
@@ -111,17 +110,17 @@ require_paths:
111
110
  - lib
112
111
  required_ruby_version: !ruby/object:Gem::Requirement
113
112
  requirements:
114
- - - ! '>='
113
+ - - '>='
115
114
  - !ruby/object:Gem::Version
116
115
  version: '0'
117
116
  required_rubygems_version: !ruby/object:Gem::Requirement
118
117
  requirements:
119
- - - ! '>='
118
+ - - '>='
120
119
  - !ruby/object:Gem::Version
121
120
  version: '0'
122
121
  requirements: []
123
122
  rubyforge_project:
124
- rubygems_version: 2.0.3
123
+ rubygems_version: 2.1.11
125
124
  signing_key:
126
125
  specification_version: 2
127
126
  summary: Encode and decode bencoded data
@@ -1,6 +0,0 @@
1
- require 'stringio'
2
- require 'bencode/parseio'
3
-
4
- class StringIO
5
- include BEncode::ParseIO
6
- end
@@ -1,9 +0,0 @@
1
- module BEncode
2
- module ParseIO
3
- def peek
4
- c = self.getc
5
- self.ungetc(c)
6
- c
7
- end
8
- end
9
- end