seven_zip_ruby 1.1.0-x64-mingw32 → 1.2.0-x64-mingw32

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: c6bed3467dce41b8cfaa3806096bf6b2f4a3b5ae
4
- data.tar.gz: d7daca75c57027da0f9b4f1b164beaff81efdc07
3
+ metadata.gz: 5f10f384b2d50f9582c13e21b88efc2cca5f31b6
4
+ data.tar.gz: f40f74f49dcaff311d4ff886a9389ab1b3ae6aec
5
5
  SHA512:
6
- metadata.gz: 7fc2297a302e79898972e45208afee9edadfec80601755f15497c4d60b61aba88668bf8bc09d44ed8dac0d4d31435fa5fd895f97cc47fc35102f49552aacb28b
7
- data.tar.gz: 253b962d9aeacbebe4e1919fee7dbf8334671b6229370a1ba03b00843a2a33a0f94ef0c93a75b0a1f87f059ab6b902fd6867cca90a11107a2c4f038f7d2c3024
6
+ metadata.gz: 1fe99ac54ad22a7cd2275dbe15503cda8ceadd2578c88d0a647707374656605fb6b26f988ac64b541e3d8200c0c8133f790f54f3cf37b3d6f49b9c07a0511b66
7
+ data.tar.gz: 3e0081737d97809b7b5c5afc0ecf16965bddbfaebd359c88813eebe6922ee07502a9e7f0cb0457dee0aa0a202efa3a4b9d38f7fa0759a7bdc7b898e13ef51d67
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  *.rbc
2
2
  *.o
3
+ *.obj
3
4
  *.so
4
5
  *.bundle
5
6
  *.bak
data/.travis.yml CHANGED
@@ -1,6 +1,15 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - "2.0.0"
4
+ - "2.1.0"
5
+ - "rbx"
6
+ - "ruby-head"
7
+ matrix:
8
+ allow_failures:
9
+ - rvm: "rbx"
10
+ - rvm: "ruby-head"
11
+ notifications:
12
+ email: false
4
13
  cache:
5
14
  - apt
6
15
  before_install:
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # SevenZipRuby ![Logo](https://raw.github.com/masamitsu-murase/seven_zip_ruby/master/resources/seven_zip_ruby_logo.png)
2
2
 
3
- [![Build Status](https://travis-ci.org/masamitsu-murase/seven_zip_ruby.png?branch=master)](https://travis-ci.org/masamitsu-murase/seven_zip_ruby)
3
+ [![Build Status](https://travis-ci.org/masamitsu-murase/seven_zip_ruby.png?branch=master)](https://travis-ci.org/masamitsu-murase/seven_zip_ruby) [![Gem Version](https://badge.fury.io/rb/seven_zip_ruby.png)](http://badge.fury.io/rb/seven_zip_ruby)
4
4
 
5
- This is a Ruby gem library to handle [7-Zip](http://www.7-zip.org) archives.
5
+ This is a Ruby gem library to extract/compress [7-Zip](http://www.7-zip.org) archives.
6
6
 
7
7
  This extension calls the native library, 7z.dll or 7z.so, internally and it is included in this gem.
8
8
 
@@ -86,12 +86,19 @@ File.open("filename.7z", "wb") do |file|
86
86
  end
87
87
  ```
88
88
 
89
- ## Supported platforms
89
+ ## Supported environment
90
+
91
+ SevenZipRuby supports the following platforms.
90
92
 
91
93
  * Windows
92
94
  * Linux
93
95
  * Mac OSX
94
96
 
97
+ SevenZipRuby supports the following Ruby engines on each platform.
98
+
99
+ * MRI 2.0.0 and later
100
+ * Rubinius 2.2.1 and later
101
+
95
102
  ## More examples
96
103
 
97
104
  ### Extract partially
@@ -180,7 +187,7 @@ LGPL and unRAR license. Please refer to LICENSE.txt.
180
187
 
181
188
  ## Releases
182
189
 
183
- * 1.1.0
190
+ * 1.1.0
184
191
  Raise error when wrong password is specified.
185
192
  * 1.0.0
186
193
  Initial release.
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  require "fileutils"
2
+ require "tempfile"
2
3
  require "bundler/gem_tasks"
3
4
 
4
5
  BINARY_FILES = [ "seven_zip_archive.so", "seven_zip_archive.bundle" ]
@@ -32,7 +33,18 @@ end
32
33
  task :build_binary do
33
34
  Dir.chdir "ext/seven_zip_ruby" do
34
35
  FileUtils.rmtree BINARY_FILES
35
- sh "ruby extconf.rb"
36
+
37
+ Tempfile.open([ "site", ".rb" ], Dir.pwd) do |temp|
38
+ temp.puts <<"EOS"
39
+ require('rbconfig')
40
+ RbConfig::CONFIG['sitearchdir'] = "../../lib"
41
+ EOS
42
+ temp.flush
43
+
44
+ sh "ruby -r#{File.expand_path(temp.path)} extconf.rb"
45
+ temp.unlink
46
+ end
47
+
36
48
  sh "#{MAKE}"
37
49
  end
38
50
  end
@@ -1,16 +1,27 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
- require_relative("seven_zip_ruby/version")
3
+ require("seven_zip_ruby/version")
4
4
 
5
- Dir.chdir("#{__dir__}/seven_zip_ruby"){ require_relative("seven_zip_ruby/seven_zip_archive") }
5
+ external_lib = (RUBY_PLATFORM.downcase.match(/mswin|mingw/) ? "7z.dll" : "7z.so")
6
+ dir = $:.find do |i|
7
+ next File.file?(File.join(i, "seven_zip_ruby", external_lib))
8
+ end
9
+ raise "Failed to find 7z.dll or 7z.so" unless (dir)
10
+
11
+ Dir.chdir(File.join(dir, "seven_zip_ruby"))do
12
+ begin
13
+ version = RUBY_VERSION.match(/\d+\.\d+/)
14
+ require("seven_zip_ruby/#{version}/seven_zip_archive")
15
+ rescue LoadError
16
+ require("seven_zip_ruby/seven_zip_archive")
17
+ end
18
+ end
6
19
  raise "Failed to initialize SevenZipRuby" unless (defined?(SevenZipRuby::SevenZipReader))
7
20
 
8
- require_relative("seven_zip_ruby/seven_zip_reader")
9
- require_relative("seven_zip_ruby/seven_zip_writer")
10
- require_relative("seven_zip_ruby/archive_info")
11
- require_relative("seven_zip_ruby/update_info")
12
- require_relative("seven_zip_ruby/entry_info")
13
- require_relative("seven_zip_ruby/exception")
21
+ require("seven_zip_ruby/seven_zip_reader")
22
+ require("seven_zip_ruby/seven_zip_writer")
23
+ require("seven_zip_ruby/archive_info")
24
+ require("seven_zip_ruby/update_info")
25
+ require("seven_zip_ruby/entry_info")
26
+ require("seven_zip_ruby/exception")
14
27
 
15
- module SevenZipRuby
16
- end
@@ -4,11 +4,12 @@ module SevenZipRuby
4
4
  class EntryInfo
5
5
  def initialize(index, path, method, dir, encrypted, anti, size, pack_size, ctime, atime, mtime, attrib, crc)
6
6
  @index, @path, @method, @dir, @encrypted, @anti, @size, @pack_size, @ctime, @atime, @mtime, @attrib, @crc =
7
- index, Pathname(path.to_s.force_encoding(Encoding::UTF_8)).cleanpath, method, dir, encrypted, anti, size, pack_size, ctime, atime, mtime, attrib, crc
7
+ index, Pathname(path.to_s.force_encoding(Encoding::UTF_8)).cleanpath.to_s, method, dir, encrypted, anti, size, pack_size, ctime, atime, mtime, attrib, crc
8
8
  end
9
9
 
10
10
  attr_reader :index, :path, :method, :size, :pack_size, :ctime, :atime, :mtime, :attrib, :crc
11
11
  alias to_i index
12
+ alias crc32 crc
12
13
 
13
14
  def directory?
14
15
  return @dir
@@ -38,7 +39,7 @@ module SevenZipRuby
38
39
  else
39
40
  type = "file"
40
41
  end
41
- str = path.to_s.encode(Encoding::ASCII, invalid: :replace, undef: :replace, replace: "?")
42
+ str = path.encode(Encoding::ASCII, invalid: :replace, undef: :replace, replace: "?")
42
43
  return "#<EntryInfo: #{index}, #{type}, #{str}>"
43
44
  end
44
45
  end
@@ -28,6 +28,11 @@ module SevenZipRuby
28
28
  # end
29
29
  # end
30
30
  #
31
+ # # Extract archive 2
32
+ # SevenZipRuby::Reader.open_file("filename.7z") do |szr|
33
+ # szr.extract(:all, "path_to_dir")
34
+ # end
35
+ #
31
36
  # # Extract encrypted archive
32
37
  # File.open("filename.7z", "rb") do |file|
33
38
  # SevenZipRuby::Reader.open(file, password: "Password String") do |szr|
@@ -103,6 +108,40 @@ module SevenZipRuby
103
108
  end
104
109
  end
105
110
 
111
+
112
+ # Open 7zip archive to read.
113
+ #
114
+ # ==== Args
115
+ # +filename+ :: Filename of 7zip archive.
116
+ # +param+ :: Optional hash parameter. <tt>:password</tt> key represents password of this archive.
117
+ #
118
+ # ==== Examples
119
+ # # Open archive
120
+ # SevenZipRuby::SevenZipReader.open_file("filename.7z") do |szr|
121
+ # # Read and extract archive.
122
+ # end
123
+ #
124
+ # # Open encrypted archive
125
+ # SevenZipRuby::SevenZipReader.open_file("filename.7z", password: "PasswordOfArchive") do |szr|
126
+ # # Read and extract archive.
127
+ # end
128
+ #
129
+ # # Open without block.
130
+ # szr = SevenZipRuby::SevenZipReader.open_file("filename.7z")
131
+ # # Read and extract archive.
132
+ # szr.close
133
+ def open_file(filename, param = {}, &block) # :yield: szr
134
+ szr = self.new
135
+ szr.open_file(filename, param)
136
+ if (block)
137
+ block.call(szr)
138
+ szr.close
139
+ else
140
+ szr
141
+ end
142
+ end
143
+
144
+
106
145
  # Open and extract 7zip archive.
107
146
  #
108
147
  # ==== Args
@@ -167,6 +206,8 @@ module SevenZipRuby
167
206
  end
168
207
  end
169
208
 
209
+ undef initialize_copy, clone, dup
210
+
170
211
  # Open 7zip archive.
171
212
  #
172
213
  # ==== Args
@@ -187,6 +228,31 @@ module SevenZipRuby
187
228
  return self
188
229
  end
189
230
 
231
+ # Open 7zip archive file.
232
+ #
233
+ # ==== Args
234
+ # +filename+ :: Filename of 7zip archive.
235
+ # +param+ :: Optional hash parameter. <tt>:password</tt> key represents password of this archive.
236
+ #
237
+ # ==== Examples
238
+ # szr = SevenZipRuby::SevenZipReader.new
239
+ # szr.open_file("filename.7z")
240
+ # # ...
241
+ # szr.close
242
+ def open_file(filename, param = {})
243
+ @stream = File.open(filename, "rb")
244
+ self.open(@stream, param)
245
+ return self
246
+ end
247
+
248
+ def close
249
+ close_impl
250
+ if (@stream)
251
+ @stream.close
252
+ @stream = nil
253
+ end
254
+ end
255
+
190
256
  # Verify 7zip archive.
191
257
  #
192
258
  # ==== Args
@@ -252,9 +318,11 @@ module SevenZipRuby
252
318
  when Symbol
253
319
  raise SevenZipError.new("Argument error") unless (index == :all)
254
320
  return extract_all(path)
255
- when Array
321
+ when Enumerable
256
322
  index_list = index.map(&:to_i).sort.uniq
257
323
  extract_files_impl(index_list, file_proc(path))
324
+ when nil
325
+ raise ArgumentError.new("Invalid parameter index")
258
326
  else
259
327
  extract_impl(index.to_i, file_proc(path))
260
328
  end
@@ -328,7 +396,7 @@ module SevenZipRuby
328
396
  extract_all_impl(data_proc(ret, idx_prj))
329
397
  return ret
330
398
 
331
- when Array
399
+ when Enumerable
332
400
  index_list = index.map(&:to_i)
333
401
  idx_prj = Hash[*(index_list.each_with_index.map{ |idx, i| [ idx, i ] }.flatten)]
334
402
 
@@ -336,6 +404,9 @@ module SevenZipRuby
336
404
  extract_files_impl(index_list, data_proc(ret, idx_prj))
337
405
  return ret
338
406
 
407
+ when nil
408
+ raise ArgumentError.new("Invalid parameter index")
409
+
339
410
  else
340
411
  index = index.to_i
341
412
  item = entry(index)
@@ -360,14 +431,15 @@ module SevenZipRuby
360
431
  case(type)
361
432
  when :stream
362
433
  ret = nil
434
+ arg_path = Pathname(arg.path)
363
435
  if (arg.anti?)
364
- arg.path.rmtree if (arg.path.exist?)
436
+ arg_path.rmtree if (arg_path.exist?)
365
437
  elsif (arg.file?)
366
- path = arg.path.expand_path(base_dir)
438
+ path = arg_path.expand_path(base_dir)
367
439
  path.parent.mkpath
368
440
  ret = File.open(path, "wb")
369
441
  else
370
- path = arg.path.expand_path(base_dir)
442
+ path = arg_path.expand_path(base_dir)
371
443
  path.mkpath
372
444
  set_file_attribute(path.to_s, arg.attrib) if (arg.attrib)
373
445
  path.utime(arg.atime || path.atime, arg.mtime || path.mtime)
@@ -379,7 +451,7 @@ module SevenZipRuby
379
451
  raise InvalidArchive.new("Corrupted archive or invalid password") unless (arg[:success])
380
452
 
381
453
  unless (arg[:info].anti?)
382
- path = arg[:info].path.expand_path(base_dir)
454
+ path = Pathname(arg[:info].path).expand_path(base_dir)
383
455
  set_file_attribute(path.to_s, arg[:info].attrib) if (arg[:info].attrib)
384
456
  path.utime(arg[:info].atime || path.atime, arg[:info].mtime || path.mtime)
385
457
  end
@@ -22,6 +22,14 @@ module SevenZipRuby
22
22
  # end
23
23
  # end
24
24
  #
25
+ # # Compress files 2
26
+ # SevenZipRuby::SevenZipWriter.open_file("filename.7z") do |szw|
27
+ # szw.add_directory("test_dir")
28
+ # Dir.chdir("parent_dir_of_test.txt") do
29
+ # szw.add_file("test.txt")
30
+ # end
31
+ # end
32
+ #
25
33
  # stream = StringIO.new("")
26
34
  # SevenZipRuby::SevenZipWriter.open(stream) do |szw|
27
35
  # szw.add_file("test.txt")
@@ -46,7 +54,11 @@ module SevenZipRuby
46
54
  # Encoding used for path string in 7zip archive.
47
55
  PATH_ENCODING = Encoding::UTF_8
48
56
 
57
+ @use_native_input_file_stream = true
58
+
49
59
  class << self
60
+ attr_accessor :use_native_input_file_stream
61
+
50
62
  # Open 7zip archive to write.
51
63
  #
52
64
  # ==== Args
@@ -75,9 +87,49 @@ module SevenZipRuby
75
87
  szw = self.new
76
88
  szw.open(stream, param)
77
89
  if (block)
78
- block.call(szw)
79
- szw.compress
80
- szw.close
90
+ begin
91
+ block.call(szw)
92
+ szw.compress
93
+ szw.close
94
+ ensure
95
+ szw.close_file
96
+ end
97
+ else
98
+ szw
99
+ end
100
+ end
101
+
102
+ # Open 7zip archive file.
103
+ #
104
+ # ==== Args
105
+ # +filename+ :: 7zip archive filename.
106
+ # +param+ :: Optional hash parameter. <tt>:password</tt> key represents password of this archive.
107
+ #
108
+ # ==== Examples
109
+ # # Open archive
110
+ # SevenZipRuby::SevenZipWriter.open_file("filename.7z") do |szw|
111
+ # # Create archive.
112
+ # # ...
113
+ # # You don't have to call szw.compress. Of cource, you may call it.
114
+ # # szw.compress
115
+ # end
116
+ #
117
+ # # Open without block.
118
+ # szw = SevenZipRuby::SevenZipWriter.open_file("filename.7z")
119
+ # # Create archive.
120
+ # szw.compress # Compress must be called in this case.
121
+ # szw.close
122
+ def open_file(filename, param = {}, &block) # :yield: szw
123
+ szw = self.new
124
+ szw.open_file(filename, param)
125
+ if (block)
126
+ begin
127
+ block.call(szw)
128
+ szw.compress
129
+ szw.close
130
+ ensure
131
+ szw.close_file
132
+ end
81
133
  else
82
134
  szw
83
135
  end
@@ -96,8 +148,10 @@ module SevenZipRuby
96
148
  # SevenZipRuby::SevenZipWriter.add_directory(file, 'dir')
97
149
  # end
98
150
  def add_directory(stream, dir, param = {})
99
- password = { password: param.delete(:password) }
100
- self.open(stream, password) do |szw|
151
+ open_param = {
152
+ password: param.delete(:password)
153
+ }
154
+ self.open(stream, open_param) do |szw|
101
155
  szw.add_directory(dir, param)
102
156
  end
103
157
  end
@@ -116,13 +170,17 @@ module SevenZipRuby
116
170
  # SevenZipRuby::SevenZipWriter.add_file(file, 'file.txt')
117
171
  # end
118
172
  def add_file(stream, filename, param = {})
119
- password = { password: param.delete(:password) }
120
- self.open(stream, password) do |szw|
173
+ open_param = {
174
+ password: param.delete(:password)
175
+ }
176
+ self.open(stream, open_param) do |szw|
121
177
  szw.add_file(filename, param)
122
178
  end
123
179
  end
124
180
  end
125
181
 
182
+ undef initialize_copy, clone, dup
183
+
126
184
  # Open 7zip archive to create.
127
185
  #
128
186
  # ==== Args
@@ -131,7 +189,8 @@ module SevenZipRuby
131
189
  #
132
190
  # ==== Examples
133
191
  # File.open("filename.7z", "wb") do |file|
134
- # szw = SevenZipRuby::SevenZipWriter.open(file)
192
+ # szw = SevenZipRuby::SevenZipWriter.new
193
+ # szw.open(file)
135
194
  # # ...
136
195
  # szw.compress
137
196
  # szw.close
@@ -142,6 +201,36 @@ module SevenZipRuby
142
201
  return self
143
202
  end
144
203
 
204
+ # Open 7zip archive file to create.
205
+ #
206
+ # ==== Args
207
+ # +filename+ :: 7zip archive filename.
208
+ # +param+ :: Optional hash parameter. <tt>:password</tt> key represents password of this archive.
209
+ #
210
+ # ==== Examples
211
+ # szw = SevenZipRuby::SevenZipWriter.new
212
+ # szw.open_file("filename.7z")
213
+ # # ...
214
+ # szw.compress
215
+ # szw.close
216
+ def open_file(filename, param = {})
217
+ @stream = File.open(filename, "wb")
218
+ self.open(@stream, param)
219
+ return self
220
+ end
221
+
222
+ def close
223
+ close_impl
224
+ close_file
225
+ end
226
+
227
+ def close_file # :nodoc:
228
+ if (@stream)
229
+ @stream.close rescue nil
230
+ @stream = nil
231
+ end
232
+ end
233
+
145
234
  # Compress and output data to archive file.
146
235
  # You don't have to call this method when you use block-style SevenZipWriter.open.
147
236
  #
@@ -261,7 +350,10 @@ module SevenZipRuby
261
350
  mkdir(directory, { ctime: directory.ctime, atime: directory.atime, mtime: directory.mtime })
262
351
  end
263
352
 
264
- Pathname.glob(directory.join("**", "*").to_s) do |entry|
353
+ Pathname.glob(directory.join("**", "*").to_s, File::FNM_DOTMATCH) do |entry|
354
+ basename = entry.basename.to_s
355
+ next if (basename == "." || basename == "..")
356
+
265
357
  name = (base_dir + entry.relative_path_from(directory)).cleanpath if (base_dir)
266
358
 
267
359
  if (entry.file?)
@@ -312,9 +404,14 @@ module SevenZipRuby
312
404
  case(type)
313
405
  when :stream
314
406
  if (info.buffer?)
315
- next StringIO.new(info.data)
407
+ # type(filename/io), data
408
+ next [ false, StringIO.new(info.data) ]
316
409
  elsif (info.file?)
317
- next File.open(info.data, "rb")
410
+ if (SevenZipWriter.use_native_input_file_stream)
411
+ next [ true, info.data ]
412
+ else
413
+ next [ false, File.open(info.data, "rb") ]
414
+ end
318
415
  else
319
416
  next nil
320
417
  end
@@ -1,3 +1,3 @@
1
1
  module SevenZipRuby
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -13,11 +13,13 @@ describe SevenZipRuby do
13
13
  end
14
14
 
15
15
  before(:each) do
16
+ @use_native_input_file_stream = SevenZipRuby::SevenZipWriter.use_native_input_file_stream
16
17
  SevenZipRubySpecHelper.prepare_each
17
18
  end
18
19
 
19
20
  after(:each) do
20
21
  SevenZipRubySpecHelper.cleanup_each
22
+ SevenZipRuby::SevenZipWriter.use_native_input_file_stream = @use_native_input_file_stream
21
23
  end
22
24
 
23
25
 
@@ -32,7 +34,7 @@ describe SevenZipRuby do
32
34
  expect(entries.size).to be SevenZipRubySpecHelper::SAMPLE_DATA.size
33
35
 
34
36
  SevenZipRubySpecHelper::SAMPLE_DATA.each do |sample|
35
- entry = entries.select{ |i| i.path == Pathname(sample[:name]).cleanpath }
37
+ entry = entries.select{ |i| i.path == Pathname(sample[:name]).cleanpath.to_s }
36
38
  expect(entry.size).to be 1
37
39
 
38
40
  entry = entry[0]
@@ -58,14 +60,12 @@ describe SevenZipRuby do
58
60
  end
59
61
 
60
62
  example "extract data directly from archive" do
61
- File.open(SevenZipRubySpecHelper::SEVEN_ZIP_FILE, "rb") do |file|
62
- SevenZipRuby::SevenZipReader.open(file) do |szr|
63
- entries = szr.entries
63
+ SevenZipRuby::SevenZipReader.open_file(SevenZipRubySpecHelper::SEVEN_ZIP_FILE) do |szr|
64
+ entries = szr.entries
64
65
 
65
- SevenZipRubySpecHelper::SAMPLE_DATA.each do |sample|
66
- entry = entries.find{ |i| i.path == Pathname(sample[:name]).cleanpath }
67
- expect(szr.extract_data(entry.index)).to eq sample[:data]
68
- end
66
+ SevenZipRubySpecHelper::SAMPLE_DATA.each do |sample|
67
+ entry = entries.find{ |i| i.path == Pathname(sample[:name]).cleanpath.to_s }
68
+ expect(szr.extract_data(entry.index)).to eq sample[:data]
69
69
  end
70
70
  end
71
71
  end
@@ -105,7 +105,7 @@ describe SevenZipRuby do
105
105
  th = Thread.new do
106
106
  szr = SevenZipRuby::SevenZipReader.open(file)
107
107
  sample = SevenZipRubySpecHelper::SAMPLE_DATA.sample
108
- entry = szr.entries.find{ |i| i.path == Pathname(sample[:name]).cleanpath }
108
+ entry = szr.entries.find{ |i| i.path == Pathname(sample[:name]).cleanpath.to_s }
109
109
  end
110
110
  th.join
111
111
 
@@ -122,9 +122,10 @@ describe SevenZipRuby do
122
122
  expect(SevenZipRuby::SevenZipReader.verify(StringIO.new(data))).to eq true
123
123
 
124
124
  data[0x27] = 0xEB.chr # This highly dependes on the current test binary.
125
+ expected = [ :DataError, :DataError, :DataError, :DataError, :DataError, :DataError, :DataError, true, true, true, true, true ]
125
126
  SevenZipRuby::SevenZipReader.open(StringIO.new(data)) do |szr|
126
127
  expect(szr.test).to eq false
127
- expect(szr.verify_detail).to eq [ :DataError, :DataError, :DataError, true, true, true ]
128
+ expect(szr.verify_detail).to eq expected
128
129
  end
129
130
 
130
131
 
@@ -137,8 +138,9 @@ describe SevenZipRuby do
137
138
  expect(szr.verify).to eq false
138
139
  end
139
140
 
141
+ expected = [ :DataError, :DataError, :DataError, :DataError, :DataError, :DataError, :DataError, true, true, true, true, true ]
140
142
  SevenZipRuby::SevenZipReader.open(StringIO.new(data), { password: "wrong password" }) do |szr|
141
- expect(szr.verify_detail).to eq [ :DataError, :DataError, :DataError, true, true, true ]
143
+ expect(szr.verify_detail).to eq expected
142
144
  end
143
145
  end
144
146
 
@@ -158,6 +160,22 @@ describe SevenZipRuby do
158
160
  end
159
161
  end
160
162
 
163
+ example "invalid index" do
164
+ File.open(SevenZipRubySpecHelper::SEVEN_ZIP_FILE, "rb") do |file|
165
+ SevenZipRuby::SevenZipReader.open(file) do |szr|
166
+ expect{ szr.extract_data(nil) }.to raise_error (ArgumentError)
167
+ end
168
+ end
169
+ end
170
+
171
+ example "invalid index for entry" do
172
+ File.open(SevenZipRubySpecHelper::SEVEN_ZIP_FILE, "rb") do |file|
173
+ SevenZipRuby::SevenZipReader.open(file) do |szr|
174
+ expect{ szr.entry("a") }.to raise_error
175
+ end
176
+ end
177
+ end
178
+
161
179
  example "invalid password" do
162
180
  File.open(SevenZipRubySpecHelper::SEVEN_ZIP_PASSWORD_FILE, "rb") do |file|
163
181
  expect{ SevenZipRuby::Reader.open(file){ |szr| szr.extract_data(1) } }.to raise_error
@@ -235,19 +253,11 @@ describe SevenZipRuby do
235
253
 
236
254
  sleep 1
237
255
  expect{ th.kill }.not_to raise_error # Thread can be killed.
256
+ end
238
257
 
239
-
240
- th = Thread.start do
241
- SevenZipRuby::SevenZipWriter.open(output) do |szw|
242
- szw.method = "BZIP2"
243
- szw.level = 9
244
- szw.multi_thread = false
245
- szw.add_data(SevenZipRubySpecHelper::SAMPLE_LARGE_RANDOM_DATA * 2, "hoge.txt")
246
- end
247
- end
248
-
249
- sleep 0.1 # Highly dependes on CPU speed...
250
- expect{ th.kill }.not_to raise_error # Thread can be killed.
258
+ example "clone and dup cannot be called." do
259
+ expect{ SevenZipRuby::SevenZipReader.new.clone }.to raise_error
260
+ expect{ SevenZipRuby::SevenZipReader.new.dup }.to raise_error
251
261
  end
252
262
 
253
263
  end
@@ -266,7 +276,9 @@ describe SevenZipRuby do
266
276
  szw.mkdir("hoge/hoge/hoge")
267
277
  szw.compress
268
278
  szw.close
269
- output.close
279
+
280
+ output.rewind
281
+ expect(SevenZipRuby::SevenZipReader.verify(output)).to eq true
270
282
  end
271
283
 
272
284
  example "compress" do
@@ -277,6 +289,24 @@ describe SevenZipRuby do
277
289
  szw.mkdir("hoge/hoge/hoge")
278
290
  szw.compress
279
291
  end
292
+
293
+ output.rewind
294
+ expect(SevenZipRuby::SevenZipReader.verify(output)).to eq true
295
+ end
296
+
297
+ example "open_file" do
298
+ FileUtils.mkpath(SevenZipRubySpecHelper::EXTRACT_DIR)
299
+ Dir.chdir(SevenZipRubySpecHelper::EXTRACT_DIR) do
300
+ filename = "hoge.7z"
301
+
302
+ SevenZipRuby::SevenZipWriter.open_file(filename) do |szw|
303
+ szw.add_data("This is a sample.", "hoge.txt")
304
+ end
305
+
306
+ File.open(filename, "rb") do |f|
307
+ expect(SevenZipRuby::SevenZipReader.verify(f)).to eq true
308
+ end
309
+ end
280
310
  end
281
311
 
282
312
  example "compress local file" do
@@ -296,53 +326,62 @@ describe SevenZipRuby do
296
326
  end
297
327
  end
298
328
 
299
- example "add_directory" do
300
- Dir.chdir(SevenZipRubySpecHelper::SAMPLE_FILE_DIR) do
301
- output = StringIO.new("")
302
- SevenZipRuby::SevenZipWriter.open(output) do |szw|
303
- Pathname.glob("*") do |path|
304
- if (path.file?)
305
- szw.add_file(path)
306
- else
307
- szw.add_directory(path)
329
+ [ true, false ].each do |use_native_input_file_stream|
330
+ example "add_directory: use_native_input_file_stream=#{use_native_input_file_stream}" do
331
+ SevenZipRuby::SevenZipWriter.use_native_input_file_stream = use_native_input_file_stream
332
+
333
+ Dir.chdir(SevenZipRubySpecHelper::SAMPLE_FILE_DIR) do
334
+ output = StringIO.new("")
335
+ SevenZipRuby::SevenZipWriter.open(output) do |szw|
336
+ Pathname.glob("*", File::FNM_DOTMATCH) do |path|
337
+ basename = path.basename.to_s
338
+ next if (basename == "." || basename == "..")
339
+
340
+ if (path.file?)
341
+ szw.add_file(path)
342
+ else
343
+ szw.add_directory(path)
344
+ end
308
345
  end
309
346
  end
310
- end
311
347
 
312
- output.rewind
313
- SevenZipRuby::SevenZipReader.open(output) do |szr|
314
- entries = szr.entries
315
- expect(entries.size).to eq SevenZipRubySpecHelper::SAMPLE_DATA.size
316
-
317
- entries.each do |entry|
318
- entry_in_sample = SevenZipRubySpecHelper::SAMPLE_DATA.find{ |i| i[:name] == entry.path.to_s }
319
- local_entry = Pathname(File.join(SevenZipRubySpecHelper::SAMPLE_FILE_DIR, entry_in_sample[:name]))
320
- if (entry_in_sample[:directory])
321
- expect(entry.directory?).to eq true
322
- else
323
- expect(szr.extract_data(entry)).to eq File.open(entry_in_sample[:name], "rb", &:read)
348
+ output.rewind
349
+ SevenZipRuby::SevenZipReader.open(output) do |szr|
350
+ entries = szr.entries
351
+ expect(entries.size).to eq SevenZipRubySpecHelper::SAMPLE_DATA.size
352
+
353
+ entries.each do |entry|
354
+ entry_in_sample = SevenZipRubySpecHelper::SAMPLE_DATA.find{ |i| i[:name] == entry.path.to_s }
355
+ local_entry = Pathname(File.join(SevenZipRubySpecHelper::SAMPLE_FILE_DIR, entry_in_sample[:name]))
356
+ if (entry_in_sample[:directory])
357
+ expect(entry.directory?).to eq true
358
+ else
359
+ expect(szr.extract_data(entry)).to eq File.open(entry_in_sample[:name], "rb", &:read)
360
+ end
361
+ expect(entry.mtime.to_i).to eq local_entry.mtime.to_i
324
362
  end
325
- expect(entry.mtime.to_i).to eq local_entry.mtime.to_i
326
363
  end
327
364
  end
328
365
  end
329
- end
330
366
 
331
- example "add_directory singleton version" do
332
- dir = File.join(SevenZipRubySpecHelper::SAMPLE_FILE_DIR, "..")
333
- dirname = File.basename(SevenZipRubySpecHelper::SAMPLE_FILE_DIR)
334
- Dir.chdir(dir) do
335
- output = StringIO.new("")
336
- SevenZipRuby::SevenZipWriter.add_directory(output, dirname)
367
+ example "add_directory singleton version: use_native_input_file_stream=#{use_native_input_file_stream}" do
368
+ SevenZipRuby::SevenZipWriter.use_native_input_file_stream = use_native_input_file_stream
337
369
 
338
- output2 = StringIO.new("")
339
- SevenZipRuby::SevenZipWriter.open(output2) do |szr|
340
- szr.add_directory(dirname)
341
- end
370
+ dir = File.join(SevenZipRubySpecHelper::SAMPLE_FILE_DIR, "..")
371
+ dirname = File.basename(SevenZipRubySpecHelper::SAMPLE_FILE_DIR)
372
+ Dir.chdir(dir) do
373
+ output = StringIO.new("")
374
+ SevenZipRuby::SevenZipWriter.add_directory(output, dirname)
375
+
376
+ output2 = StringIO.new("")
377
+ SevenZipRuby::SevenZipWriter.open(output2) do |szr|
378
+ szr.add_directory(dirname)
379
+ end
342
380
 
343
- expect(output.string).to eq output2.string
381
+ expect(output.string).to eq output2.string
382
+ end
344
383
  end
345
- end
384
+ end # use_native_input_file_stream
346
385
 
347
386
  example "use as option" do
348
387
  output = StringIO.new("")
@@ -354,15 +393,16 @@ describe SevenZipRuby do
354
393
  SevenZipRuby::SevenZipReader.open(output) do |szr|
355
394
  base_dir = Pathname(SevenZipRubySpecHelper::SAMPLE_FILE_DIR)
356
395
  entries = szr.entries
357
- files = Pathname.glob(base_dir.to_s + "/**/*") +[ base_dir ]
396
+ files = Pathname.glob(base_dir.to_s + "/**/*", File::FNM_DOTMATCH) + [ base_dir ]
397
+ files = files.select{ |i| i.basename.to_s != "." && i.basename.to_s != ".." }
358
398
 
359
399
  expect(entries.size).to eq files.size
360
400
 
361
- expect(entries.all?{ |i| i.path.to_s.start_with?("test/dir") }).to eq true
401
+ expect(entries.all?{ |i| i.path.start_with?("test/dir") }).to eq true
362
402
 
363
403
  entries.each do |entry|
364
404
  file = files.find do |i|
365
- i.relative_path_from(base_dir) == entry.path.relative_path_from(Pathname("test/dir"))
405
+ i.relative_path_from(base_dir) == Pathname(entry.path).relative_path_from(Pathname("test/dir"))
366
406
  end
367
407
  expect(file.directory?).to eq entry.directory?
368
408
  end
@@ -493,6 +533,41 @@ describe SevenZipRuby do
493
533
  expect{ szw.add_data("This is hoge.txt content.", "hoge.txt") }.to raise_error(SevenZipRuby::InvalidOperation)
494
534
  end
495
535
 
536
+ example "clone and dup cannot be called." do
537
+ expect{ SevenZipRuby::SevenZipWriter.new.clone }.to raise_error
538
+ expect{ SevenZipRuby::SevenZipWriter.new.dup }.to raise_error
539
+ end
540
+
541
+ if (false && RUBY_ENGINE == "ruby")
542
+ # It seems that Rubinius has the different way to handle error.
543
+ # Therefore, it sometimes fails to kill SevenZipRuby thread.
544
+ example "kill thread" do
545
+ [ "LZMA", "PPMd", "BZIP2" ].each do |method|
546
+ prc = lambda do
547
+ output = StringIO.new("")
548
+ SevenZipRuby::SevenZipWriter.open(output) do |szw|
549
+ szw.method = method
550
+ szw.level = 9
551
+ szw.multi_thread = true
552
+ szw.add_data(SevenZipRubySpecHelper::SAMPLE_LARGE_RANDOM_DATA * 3, "hoge.txt")
553
+ end
554
+ end
555
+
556
+ start = Time.now
557
+ th = Thread.start{ prc.call }
558
+ th.join
559
+ diff = Time.now - start
560
+
561
+ 10.times do
562
+ th = Thread.start{ prc.call }
563
+ sleep(rand * diff)
564
+ expect{ th.kill }.not_to raise_error # Thread can be killed.
565
+ sleep diff*2 # Workaround. When some threads of SZR are running and killed, SEGV sometimes occurs...
566
+ end
567
+ end
568
+ end
569
+ end
570
+
496
571
  end
497
572
 
498
573
  end
@@ -6,8 +6,8 @@ require("rbconfig")
6
6
  module SevenZipRubySpecHelper
7
7
  DETAIL_CHECK = true
8
8
 
9
- BASE_DIR = __dir__
10
- TEMP_DIR = File.expand_path("../tmp", __dir__)
9
+ BASE_DIR = File.expand_path("..", __FILE__)
10
+ TEMP_DIR = File.expand_path("../../tmp", __FILE__)
11
11
 
12
12
  SAMPLE_FILE_DIR_RELATIVE = "sample_file"
13
13
  SAMPLE_FILE_DIR = File.expand_path(SAMPLE_FILE_DIR_RELATIVE, TEMP_DIR)
@@ -21,6 +21,12 @@ module SevenZipRubySpecHelper
21
21
  { name: "directory", directory: true },
22
22
  { name: "directory/utf8_file.txt", data: "日本語のファイル".force_encoding("ASCII-8BIT"), directory: false },
23
23
  { name: "directory/utf8_name®.txt", data: "日本語のファイル".force_encoding("ASCII-8BIT"), directory: false },
24
+ { name: "directory/.dot.txt", data: "Dot text".force_encoding("ASCII-8BIT"), directory: false },
25
+ { name: "directory/.dot_dir", directory: true },
26
+ { name: "directory/.dot_dir/normal.txt", data: "Dot text".force_encoding("ASCII-8BIT"), directory: false },
27
+ { name: ".dot_dir", directory: true },
28
+ { name: ".dot_dir/normal.txt", data: "Normal text".force_encoding("ASCII-8BIT"), directory: false },
29
+ { name: ".dot_dir/.dot.txt", data: "Dot text".force_encoding("ASCII-8BIT"), directory: false },
24
30
  { name: "empty_directory", directory: true }
25
31
  ]
26
32
 
@@ -70,8 +76,9 @@ module SevenZipRubySpecHelper
70
76
 
71
77
  def prepare_seven_zip_file
72
78
  Dir.chdir(SAMPLE_FILE_DIR) do
73
- my_system("7z a -bd \"#{SEVEN_ZIP_FILE}\" *")
74
- my_system("7z a -bd \"-p#{SEVEN_ZIP_PASSWORD}\" \"#{SEVEN_ZIP_PASSWORD_FILE}\" *")
79
+ files = (Dir.glob("*", File::FNM_DOTMATCH).to_a - [ ".", ".." ]).join(" ")
80
+ my_system("7z a -bd \"#{SEVEN_ZIP_FILE}\" #{files}")
81
+ my_system("7z a -bd \"-p#{SEVEN_ZIP_PASSWORD}\" \"#{SEVEN_ZIP_PASSWORD_FILE}\" #{files}")
75
82
  end
76
83
  end
77
84
 
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.1.0
4
+ version: 1.2.0
5
5
  platform: x64-mingw32
6
6
  authors:
7
7
  - Masamitsu MURASE
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-07 00:00:00.000000000 Z
11
+ date: 2014-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -79,7 +79,7 @@ files:
79
79
  - seven_zip_ruby.gemspec
80
80
  - spec/seven_zip_ruby_spec.rb
81
81
  - spec/seven_zip_ruby_spec_helper.rb
82
- - lib/seven_zip_ruby/seven_zip_archive.so
82
+ - lib/seven_zip_ruby/2.0/seven_zip_archive.so
83
83
  homepage: https://github.com/masamitsu-murase/seven_zip_ruby
84
84
  licenses:
85
85
  - LGPL + unRAR
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  version: '0'
101
101
  requirements: []
102
102
  rubyforge_project:
103
- rubygems_version: 2.0.3
103
+ rubygems_version: 2.0.14
104
104
  signing_key:
105
105
  specification_version: 4
106
106
  summary: This is a gem library to read and write 7-Zip files.