mktorrent 1.6.2 → 1.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mktorrent.rb +7 -4
- data/test/mktorrent_acceptance_test.rb +6 -0
- data/test/mktorrent_test.rb +1 -1
- data/test/test_helper.rb +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77a407ad2f074deddd8b6e6bdbce1597f8c17663
|
4
|
+
data.tar.gz: 32614d20a89d1598dd993c7bd30f68a6ef2592e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 567a4b4b6ea9dd3d9b31f9af8893be1e46f130a67b88220e4750ca2fffb574650e8ffb220e8e3c35f88ff301f4983c22879696b3c7257ab3ee9db234a33c6008
|
7
|
+
data.tar.gz: 85c02051c564166c4039ec3ecfc640eccc5aa1f83cd8f3c9af64ea123459edaea46805858cf0e904f4c2ed347e4ded6414e14dd481297ab394d8b092d7e4dcac
|
data/lib/mktorrent.rb
CHANGED
@@ -9,7 +9,7 @@ require 'uri'
|
|
9
9
|
#t.write_torrent("~/Downloads/mytorrent.torrent")
|
10
10
|
|
11
11
|
class Torrent
|
12
|
-
attr_reader :torrent_file
|
12
|
+
attr_reader :torrent_file, :infohash
|
13
13
|
attr_accessor :info, :filehashes, :piecelength, :files, :defaultdir, :tracker, :size, :privacy, :webseed
|
14
14
|
|
15
15
|
# optionally initialize filename
|
@@ -40,6 +40,7 @@ class Torrent
|
|
40
40
|
buffer = ""
|
41
41
|
files.each do |f|
|
42
42
|
f = File.join(@dirbase, f) unless @dirbase.empty?
|
43
|
+
next if File.directory?(f)
|
43
44
|
File.open(f) do |fh|
|
44
45
|
begin
|
45
46
|
read = fh.read(length - buffer.length)
|
@@ -74,10 +75,8 @@ class Torrent
|
|
74
75
|
@info[:info][:pieces] = ""
|
75
76
|
@info.merge({ "url-list" => @webseed }) unless @webseed.empty?
|
76
77
|
if @files.count > 0
|
77
|
-
i = 0
|
78
78
|
read_pieces(all_files, @piecelength) do |piece|
|
79
79
|
@info[:info][:pieces] += Digest::SHA1.digest(piece)
|
80
|
-
i += 1
|
81
80
|
end
|
82
81
|
end
|
83
82
|
end
|
@@ -88,7 +87,7 @@ class Torrent
|
|
88
87
|
open(@torrent_file, 'wb') do |file|
|
89
88
|
file.write self.to_s
|
90
89
|
end
|
91
|
-
|
90
|
+
set_infohash
|
92
91
|
end
|
93
92
|
|
94
93
|
# Return the .torrent file as a string
|
@@ -173,4 +172,8 @@ class Torrent
|
|
173
172
|
|
174
173
|
path_for_torrent
|
175
174
|
end
|
175
|
+
|
176
|
+
def set_infohash
|
177
|
+
@infohash = Digest::SHA1.hexdigest @info[:info].bencode
|
178
|
+
end
|
176
179
|
end
|
@@ -25,6 +25,12 @@ class MktorrentAcceptanceTest < Minitest::Test
|
|
25
25
|
assert_operator Dir.entries(VALIDPATH).count, :>, 3 # At least one file, include '.' and '..'
|
26
26
|
end
|
27
27
|
|
28
|
+
# EXPECTED_INFOHASH can be found in the test_helper. It should be updated if you
|
29
|
+
# make any changes to the test data
|
30
|
+
def test_correct_infohash
|
31
|
+
assert_equal EXPECTED_INFOHASH, @torrent.infohash
|
32
|
+
end
|
33
|
+
|
28
34
|
def test_torrent_passes_acceptance
|
29
35
|
assert File.exist?(@torrent.torrent_file)
|
30
36
|
command = set_validation_command!
|
data/test/mktorrent_test.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -12,6 +12,7 @@ Minitest::Reporters.use! [
|
|
12
12
|
|
13
13
|
TRACKER = "http://test.example.com"
|
14
14
|
WEBSEED = "http://seed.example.com/webseed"
|
15
|
+
EXPECTED_INFOHASH = "a8036d51ada8fb699c9f29d7861e5589f2d20cf9"
|
15
16
|
VALIDPATH = File.expand_path("#{File.dirname(__FILE__)}/test_data")
|
16
17
|
VALIDFILEPATH = File.expand_path("#{File.dirname(__FILE__)}/test_data/sample_file1.vhd")
|
17
18
|
VALIDFILE2PATH = File.expand_path("#{File.dirname(__FILE__)}/test_data/sample_file2.vhd")
|