seven_zip_ruby 1.2.0 → 1.2.1

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: 576e8ef01f360932073896eb2ada1386f998f644
4
- data.tar.gz: 1ec0d7e51e795d61062c969126c206025e6734d4
3
+ metadata.gz: fc520a330afc1504a227c21446eaa410dc2b130c
4
+ data.tar.gz: faa164047f17bec951a944433a6c9d7276a9fa92
5
5
  SHA512:
6
- metadata.gz: d46d87711429c1cdf191efdf8bed3c0077de239fe7934b8d1fa619f9fcadedd11d026b9b38dfd8a3ecf44af27e85e9be563a8df0432a24cc03939d9308e684be
7
- data.tar.gz: 4164be8cbd6877ee638369385027c5ac232db25d3c784a11d9a4d80413076f8fedef31fdae86fce7ee5933ad7047ec41d853e504e39729b6a324b5aa198a7d83
6
+ metadata.gz: 5bb85502e25cc0146b8e0238bdf853549a3b62ce1b8a2e9d7ac4485ad2fbd1a900fe66fd2a116cc1b6192194f067b73dc1cfb3be36af5971c92ed75fc2c7167c
7
+ data.tar.gz: b32b40db99b37c8fcf39beca6f47ffb363f2fcab3a5bdd8f8aa6ccedd13b6f1c7abbf22d3bf55aec30ae68877579095cf9790618d46ec99df33ec21afbac781d
@@ -1,4 +1,5 @@
1
1
  require("stringio")
2
+ require("thread")
2
3
 
3
4
  module SevenZipRuby
4
5
 
@@ -165,7 +166,7 @@ module SevenZipRuby
165
166
  def extract(stream, index, dir = ".", param = {})
166
167
  password = { password: param.delete(:password) }
167
168
  self.open(stream, password) do |szr|
168
- szr.extract(index, dir, param)
169
+ szr.extract(index, dir)
169
170
  end
170
171
  end
171
172
 
@@ -183,7 +184,7 @@ module SevenZipRuby
183
184
  def extract_all(stream, dir = ".", param = {})
184
185
  password = { password: param.delete(:password) }
185
186
  self.open(stream, password) do |szr|
186
- szr.extract_all(dir, param)
187
+ szr.extract_all(dir)
187
188
  end
188
189
  end
189
190
 
@@ -267,7 +268,9 @@ module SevenZipRuby
267
268
  # end
268
269
  def test
269
270
  begin
270
- return test_all_impl(nil)
271
+ synchronize do
272
+ return test_all_impl(nil)
273
+ end
271
274
  rescue
272
275
  return false
273
276
  end
@@ -288,7 +291,9 @@ module SevenZipRuby
288
291
  # end
289
292
  def verify_detail
290
293
  begin
291
- return test_all_impl(true)
294
+ synchronize do
295
+ return test_all_impl(true)
296
+ end
292
297
  rescue
293
298
  return nil
294
299
  end
@@ -320,11 +325,15 @@ module SevenZipRuby
320
325
  return extract_all(path)
321
326
  when Enumerable
322
327
  index_list = index.map(&:to_i).sort.uniq
323
- extract_files_impl(index_list, file_proc(path))
328
+ synchronize do
329
+ extract_files_impl(index_list, file_proc(path))
330
+ end
324
331
  when nil
325
332
  raise ArgumentError.new("Invalid parameter index")
326
333
  else
327
- extract_impl(index.to_i, file_proc(path))
334
+ synchronize do
335
+ extract_impl(index.to_i, file_proc(path))
336
+ end
328
337
  end
329
338
  end
330
339
 
@@ -340,7 +349,9 @@ module SevenZipRuby
340
349
  # end
341
350
  # end
342
351
  def extract_all(dir = ".")
343
- extract_all_impl(file_proc(File.expand_path(dir)))
352
+ synchronize do
353
+ extract_all_impl(file_proc(File.expand_path(dir)))
354
+ end
344
355
  end
345
356
 
346
357
  # Extract entires of 7zip archive to local directory based on the block return value.
@@ -393,7 +404,9 @@ module SevenZipRuby
393
404
  end
394
405
 
395
406
  ret = []
396
- extract_all_impl(data_proc(ret, idx_prj))
407
+ synchronize do
408
+ extract_all_impl(data_proc(ret, idx_prj))
409
+ end
397
410
  return ret
398
411
 
399
412
  when Enumerable
@@ -401,7 +414,9 @@ module SevenZipRuby
401
414
  idx_prj = Hash[*(index_list.each_with_index.map{ |idx, i| [ idx, i ] }.flatten)]
402
415
 
403
416
  ret = []
404
- extract_files_impl(index_list, data_proc(ret, idx_prj))
417
+ synchronize do
418
+ extract_files_impl(index_list, data_proc(ret, idx_prj))
419
+ end
405
420
  return ret
406
421
 
407
422
  when nil
@@ -418,7 +433,9 @@ module SevenZipRuby
418
433
  end
419
434
 
420
435
  ret = []
421
- extract_impl(index, data_proc(ret, idx_prj))
436
+ synchronize do
437
+ extract_impl(index, data_proc(ret, idx_prj))
438
+ end
422
439
  return ret[0]
423
440
 
424
441
  end
@@ -482,6 +499,18 @@ module SevenZipRuby
482
499
  end
483
500
  end
484
501
  private :data_proc
502
+
503
+ COMPRESS_GUARD = Mutex.new # :nodoc:
504
+ def synchronize # :nodoc:
505
+ if (COMPRESS_GUARD)
506
+ COMPRESS_GUARD.synchronize do
507
+ yield
508
+ end
509
+ else
510
+ yield
511
+ end
512
+ end
513
+ private :synchronize
485
514
  end
486
515
 
487
516
 
@@ -1,4 +1,5 @@
1
1
  require("stringio")
2
+ require("thread")
2
3
 
3
4
  module SevenZipRuby
4
5
 
@@ -253,7 +254,9 @@ module SevenZipRuby
253
254
  # szw.close
254
255
  # end
255
256
  def compress
256
- compress_impl(compress_proc)
257
+ synchronize do
258
+ compress_impl(compress_proc)
259
+ end
257
260
  return self
258
261
  end
259
262
 
@@ -421,6 +424,18 @@ module SevenZipRuby
421
424
  end
422
425
  end
423
426
  private :compress_proc
427
+
428
+ COMPRESS_GUARD = Mutex.new # :nodoc:
429
+ def synchronize # :nodoc:
430
+ if (COMPRESS_GUARD)
431
+ COMPRESS_GUARD.synchronize do
432
+ yield
433
+ end
434
+ else
435
+ yield
436
+ end
437
+ end
438
+ private :synchronize
424
439
  end
425
440
 
426
441
 
@@ -1,3 +1,3 @@
1
1
  module SevenZipRuby
2
- VERSION = "1.2.0"
2
+ VERSION = "1.2.1"
3
3
  end
@@ -79,6 +79,24 @@ describe SevenZipRuby do
79
79
  end
80
80
  end
81
81
 
82
+ example "singleton method: extract" do
83
+ File.open(SevenZipRubySpecHelper::SEVEN_ZIP_FILE, "rb") do |file|
84
+ SevenZipRuby::SevenZipReader.extract(file, :all, SevenZipRubySpecHelper::EXTRACT_DIR)
85
+ end
86
+ end
87
+
88
+ example "singleton method: extract_all" do
89
+ File.open(SevenZipRubySpecHelper::SEVEN_ZIP_FILE, "rb") do |file|
90
+ SevenZipRuby::SevenZipReader.extract_all(file, SevenZipRubySpecHelper::EXTRACT_DIR)
91
+ end
92
+ end
93
+
94
+ example "singleton method: verify" do
95
+ File.open(SevenZipRubySpecHelper::SEVEN_ZIP_FILE, "rb") do |file|
96
+ SevenZipRuby::SevenZipReader.verify(file)
97
+ end
98
+ end
99
+
82
100
  example "extract archive" do
83
101
  File.open(SevenZipRubySpecHelper::SEVEN_ZIP_FILE, "rb") do |file|
84
102
  SevenZipRuby::SevenZipReader.open(file) do |szr|
@@ -144,6 +162,28 @@ describe SevenZipRuby do
144
162
  end
145
163
  end
146
164
 
165
+ example "run in multi threads" do
166
+ s = StringIO.new
167
+ SevenZipRuby::SevenZipWriter.open(s) do |szw|
168
+ szw.add_data(SevenZipRubySpecHelper::SAMPLE_LARGE_RANDOM_DATA, "data.bin")
169
+ end
170
+ data = s.string
171
+
172
+ th_list = []
173
+ 100.times do
174
+ th = Thread.new do
175
+ stream = StringIO.new(data)
176
+ SevenZipRuby::SevenZipReader.open(stream) do |szr|
177
+ szr.extract_data(0)
178
+ end
179
+ end
180
+ th_list.push(th)
181
+ end
182
+ th_list.each do |t|
183
+ t.join
184
+ end
185
+ end
186
+
147
187
 
148
188
  describe "error handling" do
149
189
 
@@ -470,6 +510,24 @@ describe SevenZipRuby do
470
510
  expect(size.sort.reverse).to eq size
471
511
  end
472
512
 
513
+ example "run in multi threads" do
514
+ th_list = []
515
+ mutex = Mutex.new
516
+ 100.times do
517
+ th = Thread.new do
518
+ stream = StringIO.new
519
+ SevenZipRuby::SevenZipWriter.open(stream) do |szw|
520
+ data = SevenZipRubySpecHelper::SAMPLE_LARGE_RANDOM_DATA
521
+ szw.add_data(data, "hoge.dat")
522
+ end
523
+ end
524
+ th_list.push(th)
525
+ end
526
+ th_list.each do |t|
527
+ t.join
528
+ end
529
+ end
530
+
473
531
  if (SevenZipRubySpecHelper.processor_count && SevenZipRubySpecHelper.processor_count > 1)
474
532
  example "set multi_thread" do
475
533
  time = [ false, true ].map do |multi_thread|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seven_zip_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masamitsu MURASE
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-13 00:00:00.000000000 Z
11
+ date: 2014-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler