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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9c56892f6cb759de12f6e04829f8985d5e08dc3d
4
- data.tar.gz: 48ce59582b8df667828598f6562024d774193c2f
3
+ metadata.gz: 77a407ad2f074deddd8b6e6bdbce1597f8c17663
4
+ data.tar.gz: 32614d20a89d1598dd993c7bd30f68a6ef2592e9
5
5
  SHA512:
6
- metadata.gz: d1f68f88860a011bdebbe20455be412fa7e8071839294874e7b8c18c201658d253c29550ec5018f882d42a97d016ebce8be3f9c5aa1c01cc76039dbec6a7811c
7
- data.tar.gz: 8cb68e2cf5d9fc35b0be3fc9d0b36656773cfcac6f08d033713136535a1a5e795551d9bb00bd4d99fc7f94a5cb4a426c0f9062d9de36328097a8668dc2323b0c
6
+ metadata.gz: 567a4b4b6ea9dd3d9b31f9af8893be1e46f130a67b88220e4750ca2fffb574650e8ffb220e8e3c35f88ff301f4983c22879696b3c7257ab3ee9db234a33c6008
7
+ data.tar.gz: 85c02051c564166c4039ec3ecfc640eccc5aa1f83cd8f3c9af64ea123459edaea46805858cf0e904f4c2ed347e4ded6414e14dd481297ab394d8b092d7e4dcac
@@ -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
- @torrent_file
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!
@@ -42,7 +42,7 @@ class MktorrentTest < Minitest::Test
42
42
 
43
43
  def test_add_directory_increments_file_count
44
44
  @torrent.add_directory(VALIDPATH)
45
- assert_equal 2, @torrent.count
45
+ assert_equal 3, @torrent.count
46
46
  end
47
47
 
48
48
  def test_add_directory_uses_relative_paths
@@ -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")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mktorrent
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.2
4
+ version: 1.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timothy Mukaibo