bencode 0.8.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +1 -0
- data/bencode.gemspec +2 -2
- data/lib/bencode/parser.rb +4 -3
- data/lib/bencode.rb +1 -1
- data/test/decoding_test.rb +4 -0
- metadata +6 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3df918cce71dce118a46f227cc80ba6b72e99b37b6ac3765786a2ce3946320d5
|
4
|
+
data.tar.gz: ec14358f50516721c80a71ea31d28a66c1fa576eb683b09e79239d60fa4d9c00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90e126ffca4d28f53c874260c596c91c13fd6d51195e6d1fc9027dbdcdb49e9917899152307a78aff72d45caf611551d77ba2c7fe505878e5e49f7ffaf475e28
|
7
|
+
data.tar.gz: b975f17c141d32da9eedce9788badd6b5155ccfc875e2ddc7a541fb22a77ded9df59906684a38d2cea76aac4fd1ecd53ff84e3392d569b80cfaf90bc78ed292f
|
data/README.md
CHANGED
data/bencode.gemspec
CHANGED
@@ -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.
|
11
|
-
s.date = '
|
10
|
+
s.version = '1.0.0'
|
11
|
+
s.date = '2024-08-12'
|
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."
|
data/lib/bencode/parser.rb
CHANGED
@@ -2,7 +2,7 @@ require 'stringio'
|
|
2
2
|
|
3
3
|
module BEncode
|
4
4
|
class Parser
|
5
|
-
attr_reader :stream
|
5
|
+
attr_reader :stream, :encoding
|
6
6
|
|
7
7
|
def initialize(stream)
|
8
8
|
@stream =
|
@@ -13,6 +13,7 @@ module BEncode
|
|
13
13
|
elsif stream.respond_to? :to_s
|
14
14
|
StringIO.new stream.to_s
|
15
15
|
end
|
16
|
+
@encoding = @stream.external_encoding || Encoding::default_external
|
16
17
|
end
|
17
18
|
|
18
19
|
def parse!
|
@@ -50,7 +51,7 @@ module BEncode
|
|
50
51
|
until peek == ?e
|
51
52
|
key = parse!
|
52
53
|
|
53
|
-
unless key.is_a? String or key.is_a?
|
54
|
+
unless key.is_a? String or key.is_a? Integer
|
54
55
|
raise BEncode::DecodeError, "key must be a string or number"
|
55
56
|
end
|
56
57
|
|
@@ -69,7 +70,7 @@ module BEncode
|
|
69
70
|
begin
|
70
71
|
length = num.chop.to_i
|
71
72
|
return "" if length == 0 # Workaround for Rubinius bug
|
72
|
-
str = stream.read(length)
|
73
|
+
str = stream.read(length).force_encoding(encoding)
|
73
74
|
rescue
|
74
75
|
raise BEncode::DecodeError, "invalid string length"
|
75
76
|
end
|
data/lib/bencode.rb
CHANGED
data/test/decoding_test.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require 'environment'
|
2
3
|
|
3
4
|
describe "decoding" do
|
@@ -14,4 +15,7 @@ describe "decoding" do
|
|
14
15
|
it_should_decode hsh, "d3:foo3:bar3:baz3:quxe"
|
15
16
|
|
16
17
|
it_should_decode 42, "i42eBOGUS", :ignore_trailing_junk => true
|
18
|
+
|
19
|
+
it_should_decode "café", "5:café"
|
20
|
+
it_should_decode ["你好", "中文"], "l6:你好6:中文e"
|
17
21
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bencode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Schierbeck
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rdoc
|
@@ -103,7 +103,7 @@ homepage: http://github.com/dasch/ruby-bencode
|
|
103
103
|
licenses:
|
104
104
|
- MIT
|
105
105
|
metadata: {}
|
106
|
-
post_install_message:
|
106
|
+
post_install_message:
|
107
107
|
rdoc_options:
|
108
108
|
- "--charset=UTF-8"
|
109
109
|
require_paths:
|
@@ -119,10 +119,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
119
|
- !ruby/object:Gem::Version
|
120
120
|
version: '0'
|
121
121
|
requirements: []
|
122
|
-
|
123
|
-
|
124
|
-
signing_key:
|
122
|
+
rubygems_version: 3.4.10
|
123
|
+
signing_key:
|
125
124
|
specification_version: 2
|
126
125
|
summary: Encode and decode bencoded data
|
127
126
|
test_files: []
|
128
|
-
has_rdoc:
|