mktorrent 1.2.0 → 1.5.0

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: 40013fae6c1b166f34155fe839dcb81ea1c9457d
4
- data.tar.gz: b48e184f27de7f03296691733da993b99fa705fa
3
+ metadata.gz: f2c1e1c11c1f953694f5c37137f7bae096fcafef
4
+ data.tar.gz: ba510aa5d85d4d5ae56a1dd603e3e218d408d156
5
5
  SHA512:
6
- metadata.gz: 2e5ea1994b7b8e5ee2609dec3d0c8e016e6962eff8399fe118c3b8df1fdb7287350c0743a430c4decb85f57148f0ac522a31050f5e6a9739e62ce577133d6beb
7
- data.tar.gz: 6c8acd9ef4d10e7fdbbe8ccb60a750f5a7433edcbbf7fd431a88b99329032885239c93f108e07e2cb02f8adb825a88036c4298d05d7ce2e06739c23b01a4f712
6
+ metadata.gz: 27a025b8b1f7c17ac729610e5b85a4c41d84d4224f510738bfa32fa04277b82aaa37fb8d01bf102b339d27a9f76e815f5aa4fca9e3b22f847e30aed317fd111d
7
+ data.tar.gz: e3a661b103900c77446bda96cb45371462eea67094f681f277298854a919f7e1082a45c213c4711a68c20f7a45ea0811c976088ffa0ca39fd977fb039eb1bffd
@@ -46,11 +46,15 @@ class Torrent
46
46
  File.open(f.join("/")) do |fh|
47
47
  begin
48
48
  read = fh.read(length - buffer.length)
49
- if (buffer.length + read.length) == length
50
- yield(buffer + read)
51
- buffer = ""
52
- else
53
- buffer += read
49
+
50
+ # Make sure file not empty
51
+ if not read.nil?
52
+ if (buffer.length + read.length) == length
53
+ yield(buffer + read)
54
+ buffer = ""
55
+ else
56
+ buffer += read
57
+ end
54
58
  end
55
59
  end until fh.eof?
56
60
  end
@@ -112,6 +116,21 @@ class Torrent
112
116
  end
113
117
  end
114
118
 
119
+ def add_directory(path)
120
+ # Using Dir.entries instead of glob so that non-escaped paths can be used
121
+ Dir.entries(path).each do |entry|
122
+ # Ignore unix current and parent directories
123
+ next if entry == '.' or entry == '..'
124
+
125
+ filename = path + File::SEPARATOR + entry
126
+ if File.directory?(filename)
127
+ add_directory(filename)
128
+ else
129
+ add_file(filename)
130
+ end
131
+ end
132
+ end
133
+
115
134
  # Need to read the files in @piecelength chunks and hash against that
116
135
  def hash_pieces(files)
117
136
  offset = 0
@@ -3,6 +3,7 @@ require File.join(File.dirname(__FILE__), '..', 'lib', 'mktorrent')
3
3
 
4
4
  class MktorrentTest < Minitest::Test
5
5
  TRACKER = "http://test.example.com"
6
+ VALIDPATH = File.expand_path("#{File.dirname(__FILE__)}/test_data")
6
7
  VALIDFILEPATH = File.expand_path("#{File.dirname(__FILE__)}/test_data/sample_file1.vhd")
7
8
  VALIDFILE2PATH = File.expand_path("#{File.dirname(__FILE__)}/test_data/sample_file2.vhd")
8
9
  VALIDFILENAME = "randomfile.vhd"
@@ -39,6 +40,11 @@ class MktorrentTest < Minitest::Test
39
40
  assert_raises(IOError) { @torrent.add_file(VALIDFILEPATH) }
40
41
  end
41
42
 
43
+ def test_add_directory
44
+ @torrent.add_directory(VALIDPATH)
45
+ assert_equal 2, @torrent.count
46
+ end
47
+
42
48
  def test_default_privacy
43
49
  @torrent.add_file(VALIDFILEPATH)
44
50
  assert_equal 0, @torrent.privacy
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mktorrent
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timothy Mukaibo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-11 00:00:00.000000000 Z
11
+ date: 2015-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bencode
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubygems-tasks
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.2.4
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.2.4
55
69
  description: Create .torrent files easily with this gem. The code is ugly, but it
56
70
  works :)
57
71
  email: timothy@mukaibo.com
@@ -81,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
95
  version: '0'
82
96
  requirements: []
83
97
  rubyforge_project:
84
- rubygems_version: 2.2.2
98
+ rubygems_version: 2.4.5
85
99
  signing_key:
86
100
  specification_version: 4
87
101
  summary: Create .torrent files easily with this gem