seven_zip_ruby 1.2.4 → 1.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 406e705d876048808c1a43bde40472e38daeda43
4
- data.tar.gz: 61fbef4bf41b1f5c0589b609e27022f4cf85e908
3
+ metadata.gz: 24d424d3f87e77974e436f6c044a54e5783baf95
4
+ data.tar.gz: f5280318feffbdc6e25222916fb1168969bd3a73
5
5
  SHA512:
6
- metadata.gz: ba40d7b46b2b3488690fc76ee4dad03c4d8f889f25f87d0f8a3e53842fb391d8a82b9d1b5672347fe2419a7c986160de475269552030c606680f12de5a3152b2
7
- data.tar.gz: e201cbd4e6b0d18db7d9fc8531a3e5840f40e3f823e71015f3709d4384e3bf224ac5c62ac88735d20ccb94050094a9489d754977aa1af4b927c4219118b97df3
6
+ metadata.gz: 2db16fba18dfa60a526bd4b03317da8a512c541e1fefb55633f785493086047ce8334b47e839a72d470e1210a51546433d1ee6e67513c5649c3d45bc7b99676b
7
+ data.tar.gz: ccaa6fec52258413febf2db20388945fe30a19d48839e7f8287a4498fbe323893250fdfb5c54c788aa8a9ea51fee2438974f1296a2453e287c8276b4a3bcb1f9
@@ -1,19 +1,35 @@
1
1
  language: ruby
2
2
  rvm:
3
- - "2.0.0"
4
- - "2.1.1"
5
- - "rbx-2"
3
+ - "2.0"
4
+ - "2.1"
5
+ - "2.2"
6
+ - "2.3.0"
7
+ - "2.3"
8
+ - "rbx-2.2.7"
6
9
  - "ruby-head"
7
10
  matrix:
8
11
  allow_failures:
9
- - rvm: "rbx-2"
12
+ - rvm: "rbx-2.2.7"
10
13
  - rvm: "ruby-head"
14
+ include:
15
+ - rvm: 2.3.1
16
+ os: osx
17
+ osx_image: xcode7.3
11
18
  notifications:
12
19
  email: false
13
20
  cache:
14
21
  - apt
15
22
  before_install:
23
+ - gem update bundler
16
24
  - bundle install --path=vendor/bundle
17
- - sudo apt-get install p7zip-full
25
+ - case $TRAVIS_OS_NAME in
26
+ linux)
27
+ sudo apt-get install p7zip-full
28
+ ;;
29
+ osx)
30
+ brew update && brew tap wk8/p7zip9.20 && brew install p7zip920
31
+ ;;
32
+ esac
33
+
18
34
  install: bundle exec rake build_local
19
35
  script: bundle exec rspec spec/seven_zip_ruby_spec.rb
data/README.md CHANGED
@@ -148,6 +148,17 @@ File.open("filename.7z", "rb") do |file|
148
148
  end
149
149
  ```
150
150
 
151
+ You can also create a self extracting archive for Windows.
152
+
153
+ ```ruby
154
+ File.open("filename.exe", "rb") do |file|
155
+ # :gui and :console can be specified as :sfx parameter.
156
+ SevenZipRuby::Writer.open(file, sfx: :gui) do |szr|
157
+ szr.add_data "file content", "file.txt"
158
+ end
159
+ end
160
+ ```
161
+
151
162
  ### Set compression mode
152
163
 
153
164
  7zip supports LZMA, LZMA2, PPMD, BZIP2, DEFLATE and COPY.
data/Rakefile CHANGED
@@ -9,7 +9,15 @@ task :build_platform => [ :pre_platform, :build, :post_platform ]
9
9
 
10
10
  task :pre_platform do
11
11
  FileUtils.mv("seven_zip_ruby.gemspec", "seven_zip_ruby.gemspec.bak")
12
- FileUtils.cp("resources/seven_zip_ruby.gemspec.platform", "seven_zip_ruby.gemspec")
12
+
13
+ versions = Dir.glob("lib/seven_zip_ruby/*").select{ |i| File.directory?(i) }.map{ |i| i.split("/").last }.sort_by{ |i| i.split(".").map(&:to_i) }
14
+ min_version = versions.first + ".0"
15
+ max_version = versions.last.split(".").first + "." + (versions.last.split(".").last.to_i + 1).to_s + ".0"
16
+ gemspec = File.open("resources/seven_zip_ruby.gemspec.platform", "r", &:read)
17
+ .gsub("SPEC_REQUIRED_RUBY_VERSION"){ "spec.required_ruby_version = [ '>= #{min_version}', '< #{max_version}' ]" }
18
+ File.open("seven_zip_ruby.gemspec", "w") do |f|
19
+ f.write(gemspec)
20
+ end
13
21
  end
14
22
 
15
23
  task :post_platform do
@@ -59,6 +59,7 @@ def sample_cpp_source
59
59
  # - lambda
60
60
  # - std::function
61
61
  # - std::array
62
+ # - memset_s defined, on Darwin and BSD
62
63
  return <<'EOS'
63
64
  #include <functional>
64
65
  #include <algorithm>
@@ -67,6 +68,11 @@ def sample_cpp_source
67
68
 
68
69
  #include <ruby.h>
69
70
 
71
+ // see the test on memset_s below, which is a purely BSD thing
72
+ #if defined(__APPLE__) || defined(BSD)
73
+ #include <string.h>
74
+ #endif
75
+
70
76
  void test()
71
77
  {
72
78
  int array[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
@@ -84,6 +90,11 @@ void test()
84
90
  });
85
91
 
86
92
  std::for_each(var_list.begin(), var_list.end(), [](int num){ std::cout << num << std::endl; });
93
+
94
+ #if defined(__APPLE__) || defined(BSD)
95
+ char str[] = "imareallycoolstringright";
96
+ memset_s(str, sizeof str, 'b', 5);
97
+ #endif
87
98
  }
88
99
  EOS
89
100
  end
@@ -135,8 +146,8 @@ def main
135
146
  # MinGW
136
147
  $LIBS = "-loleaut32 -static-libgcc -static-libstdc++"
137
148
 
138
- cpp0x_flag = [ "", "-std=c++11", "-std=gnu++11", "-std=c++0x", "-std=gnu++0x" ].find do |opt|
139
- next try_compile(sample_cpp_source, "#{opt} -x c++ ")
149
+ cpp0x_flag = [ "", "-std=gnu++11", "-std=c++11", "-std=gnu++0x", "-std=c++0x" ].find do |opt|
150
+ try_compile(sample_cpp_source, "#{opt} -x c++ ")
140
151
  end
141
152
  raise "C++11 is not supported by the compiler." unless (cpp0x_flag)
142
153
 
@@ -150,8 +161,11 @@ def main
150
161
  end
151
162
  end
152
163
 
153
- cpp0x_flag = [ "", "-std=c++11", "-std=gnu++11", "-std=c++0x", "-std=gnu++0x" ].find do |opt|
154
- next (try_compile(sample_cpp_source, "#{opt} -x c++ ") || try_compile(sample_cpp_source, "#{opt} "))
164
+ possible_cpp0x_flags = [ "", "-std=gnu++11", "-std=c++11", "-std=gnu++0x", "-std=c++0x" ].map do |opt|
165
+ ["#{opt} -x c++ ", "#{opt} "]
166
+ end.flatten
167
+ cpp0x_flag = possible_cpp0x_flags.find do |opt|
168
+ try_compile(sample_cpp_source, opt)
155
169
  end
156
170
  raise "C++11 is not supported by the compiler." unless (cpp0x_flag)
157
171
 
@@ -13,6 +13,10 @@
13
13
 
14
14
  #define INTERN(const_str) rb_intern2(const_str, sizeof(const_str) - 1)
15
15
 
16
+ // For https://bugs.ruby-lang.org/issues/11962
17
+ #ifndef RARRAY_CONST_PTR
18
+ #define RARRAY_CONST_PTR(index_list) RARRAY_PTR(index_list)
19
+ #endif
16
20
 
17
21
  ////////////////////////////////////////////////////////////////
18
22
  namespace SevenZip
@@ -505,7 +509,7 @@ VALUE ArchiveReader::extractFiles(VALUE index_list, VALUE callback_proc)
505
509
  fillEntryInfo();
506
510
 
507
511
  std::vector<UInt32> list(RARRAY_LEN(index_list));
508
- std::transform(RARRAY_PTR(index_list), RARRAY_PTR(index_list) + RARRAY_LEN(index_list),
512
+ std::transform(RARRAY_CONST_PTR(index_list), RARRAY_CONST_PTR(index_list) + RARRAY_LEN(index_list),
509
513
  list.begin(), [](VALUE num){ return NUM2ULONG(num); });
510
514
 
511
515
  HRESULT ret;
@@ -1220,14 +1224,13 @@ STDMETHODIMP ArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStrea
1220
1224
  bool ret = m_archive->runRubyAction([&](){
1221
1225
  rb_stream = rb_funcall(proc, INTERN("call"), 2,
1222
1226
  ID2SYM(INTERN("stream")), m_archive->entryInfo(index));
1227
+ m_archive->setProcessingStream(rb_stream, index, askExtractMode);
1223
1228
  });
1224
1229
  if (!ret){
1225
1230
  m_archive->clearProcessingStream();
1226
1231
  return E_FAIL;
1227
1232
  }
1228
1233
 
1229
- m_archive->setProcessingStream(rb_stream, index, askExtractMode);
1230
-
1231
1234
  OutStream *stream = new OutStream(rb_stream, m_archive);
1232
1235
  CMyComPtr<OutStream> ptr(stream);
1233
1236
  *outStream = ptr.Detach();
@@ -1434,14 +1437,14 @@ STDMETHODIMP ArchiveUpdateCallback::GetStream(UInt32 index, ISequentialInStream
1434
1437
  }else{
1435
1438
  rb_stream = rb_ary_entry(ret_array, 1);
1436
1439
  }
1440
+
1441
+ m_archive->setProcessingStream(rb_stream, index);
1437
1442
  });
1438
1443
  if (!ret){
1439
1444
  m_archive->clearProcessingStream();
1440
1445
  return E_FAIL;
1441
1446
  }
1442
1447
 
1443
- m_archive->setProcessingStream(rb_stream, index);
1444
-
1445
1448
  if (NIL_P(rb_stream) && !(filepath.empty())){
1446
1449
  FileInStream *stream = new FileInStream(filepath, m_archive);
1447
1450
  CMyComPtr<FileInStream> ptr(stream);
@@ -385,6 +385,7 @@ class ArchiveOpenCallback : public IArchiveOpenCallback, public ICryptoGetTextPa
385
385
  public:
386
386
  ArchiveOpenCallback(ArchiveReader *archive);
387
387
  ArchiveOpenCallback(ArchiveReader *archive, const std::string &password);
388
+ virtual ~ArchiveOpenCallback() {}
388
389
 
389
390
  MY_UNKNOWN_IMP2(IArchiveOpenCallback, ICryptoGetTextPassword)
390
391
 
@@ -408,6 +409,7 @@ class ArchiveExtractCallback : public IArchiveExtractCallback, public ICryptoGet
408
409
  public:
409
410
  ArchiveExtractCallback(ArchiveReader *archive);
410
411
  ArchiveExtractCallback(ArchiveReader *archive, const std::string &password);
412
+ virtual ~ArchiveExtractCallback() {}
411
413
 
412
414
  MY_UNKNOWN_IMP2(IArchiveExtractCallback, ICryptoGetTextPassword)
413
415
 
@@ -436,6 +438,7 @@ class ArchiveUpdateCallback : public IArchiveUpdateCallback, public ICryptoGetTe
436
438
  public:
437
439
  ArchiveUpdateCallback(ArchiveWriter *archive);
438
440
  ArchiveUpdateCallback(ArchiveWriter *archive, const std::string &password);
441
+ virtual ~ArchiveUpdateCallback() {}
439
442
 
440
443
  MY_UNKNOWN_IMP2(IArchiveUpdateCallback, ICryptoGetTextPassword2)
441
444
 
@@ -466,6 +469,7 @@ class InStream : public IInStream, public CMyUnknownImp
466
469
  {
467
470
  public:
468
471
  InStream(VALUE stream, ArchiveBase *archive);
472
+ virtual ~InStream() {}
469
473
 
470
474
  MY_UNKNOWN_IMP1(IInStream)
471
475
 
@@ -481,7 +485,7 @@ class FileInStream : public IInStream, public CMyUnknownImp
481
485
  {
482
486
  public:
483
487
  FileInStream(const std::string &filename, ArchiveBase *archive);
484
- ~FileInStream();
488
+ virtual ~FileInStream();
485
489
 
486
490
  MY_UNKNOWN_IMP1(IInStream)
487
491
 
@@ -502,6 +506,7 @@ class OutStream : public IOutStream, public CMyUnknownImp
502
506
  {
503
507
  public:
504
508
  OutStream(VALUE stream, ArchiveBase *archive);
509
+ virtual ~OutStream() {}
505
510
 
506
511
  MY_UNKNOWN_IMP1(IOutStream)
507
512
 
@@ -520,6 +525,7 @@ class FileOutStream : public IOutStream, public CMyUnknownImp
520
525
  {
521
526
  public:
522
527
  FileOutStream(const std::string &filename, ArchiveBase *archive);
528
+ virtual ~FileOutStream() {}
523
529
 
524
530
  MY_UNKNOWN_IMP1(IOutStream)
525
531
 
Binary file
@@ -236,6 +236,7 @@ module SevenZipRuby
236
236
  # szr.close
237
237
  # end
238
238
  def open(stream, param = {})
239
+ param = param.clone
239
240
  param[:password] = param[:password].to_s if (param[:password])
240
241
  stream.set_encoding(Encoding::ASCII_8BIT)
241
242
  open_impl(stream, param)
@@ -51,10 +51,26 @@ module SevenZipRuby
51
51
  # szw.add_directory("test_dir")
52
52
  # end
53
53
  # end
54
+ #
55
+ # === Create a sfx, a self extracting archive for Windows executable binary.
56
+ # File.open("filename.exe", "wb") do |file|
57
+ # SevenZipRuby::SevenZipWriter.open(file, sfx: true) do |szw|
58
+ # szw.add_directory("test_dir")
59
+ # end
60
+ # end
54
61
  class SevenZipWriter
55
62
  # Encoding used for path string in 7zip archive.
56
63
  PATH_ENCODING = Encoding::UTF_8
57
64
 
65
+ # Files for self extraction.
66
+ SFX_FILE_LIST = {
67
+ default: File.expand_path("../7z.sfx", __FILE__),
68
+ gui: File.expand_path("../7z.sfx", __FILE__),
69
+ console: File.expand_path("../7zCon.sfx", __FILE__)
70
+ } # :nodoc:
71
+
72
+ OPEN_PARAM_LIST = [ :password, :sfx ] # :nodoc:
73
+
58
74
  @use_native_input_file_stream = true
59
75
 
60
76
  class << self
@@ -64,10 +80,12 @@ module SevenZipRuby
64
80
  #
65
81
  # ==== Args
66
82
  # +stream+ :: Output stream to write 7zip archive. <tt>stream.write</tt> is needed.
67
- # +param+ :: Optional hash parameter. <tt>:password</tt> key represents password of this archive.
83
+ # +param+ :: Optional hash parameter.
84
+ # <tt>:password</tt> key specifies password of this archive.
85
+ # <tt>:sfx</tt> key specifies Self Extracting mode. <tt>:gui</tt> and <tt>:console</tt> can be used. <tt>true</tt> is same as <tt>:gui</tt>.
68
86
  #
69
87
  # ==== Examples
70
- # # Open archive
88
+ # # Open an archive
71
89
  # File.open("filename.7z", "wb") do |file|
72
90
  # SevenZipRuby::SevenZipWriter.open(file) do |szw|
73
91
  # # Create archive.
@@ -84,6 +102,14 @@ module SevenZipRuby
84
102
  # szw.compress # Compress must be called in this case.
85
103
  # szw.close
86
104
  # end
105
+ #
106
+ # # Create a self extracting archive. <tt>:gui</tt> and <tt>:console</tt> can be used.
107
+ # File.open("filename.7z", "wb") do |file|
108
+ # szw = SevenZipRuby::SevenZipWriter.open(file, sfx: :gui)
109
+ # # Create archive.
110
+ # szw.compress # Compress must be called in this case.
111
+ # szw.close
112
+ # end
87
113
  def open(stream, param = {}, &block) # :yield: szw
88
114
  szw = self.new
89
115
  szw.open(stream, param)
@@ -104,7 +130,9 @@ module SevenZipRuby
104
130
  #
105
131
  # ==== Args
106
132
  # +filename+ :: 7zip archive filename.
107
- # +param+ :: Optional hash parameter. <tt>:password</tt> key represents password of this archive.
133
+ # +param+ :: Optional hash parameter.
134
+ # <tt>:password</tt> key specifies password of this archive.
135
+ # <tt>:sfx</tt> key specifies Self Extracting mode. <tt>:gui</tt> and <tt>:console</tt> can be used. <tt>true</tt> is same as <tt>:gui</tt>.
108
136
  #
109
137
  # ==== Examples
110
138
  # # Open archive
@@ -141,7 +169,9 @@ module SevenZipRuby
141
169
  # ==== Args
142
170
  # +stream+ :: Output stream to write 7zip archive. <tt>stream.write</tt> is needed.
143
171
  # +dir+ :: Directory to be added to the 7zip archive. <b><tt>dir</tt></b> must be a <b>relative path</b>.
144
- # +param+ :: Optional hash parameter. <tt>:password</tt> key represents password of this archive.
172
+ # +param+ :: Optional hash parameter.
173
+ # <tt>:password</tt> key specifies password of this archive.
174
+ # <tt>:sfx</tt> key specifies Self Extracting mode. <tt>:gui</tt> and <tt>:console</tt> can be used. <tt>true</tt> is same as <tt>:gui</tt>.
145
175
  #
146
176
  # ==== Examples
147
177
  # # Create 7zip archive which includes 'dir'.
@@ -149,9 +179,11 @@ module SevenZipRuby
149
179
  # SevenZipRuby::SevenZipWriter.add_directory(file, 'dir')
150
180
  # end
151
181
  def add_directory(stream, dir, param = {})
152
- open_param = {
153
- password: param.delete(:password)
154
- }
182
+ param = param.clone
183
+ open_param = {}
184
+ OPEN_PARAM_LIST.each do |key|
185
+ open_param[key] = param.delete(key) if param.key?(key)
186
+ end
155
187
  self.open(stream, open_param) do |szw|
156
188
  szw.add_directory(dir, param)
157
189
  end
@@ -163,7 +195,9 @@ module SevenZipRuby
163
195
  # ==== Args
164
196
  # +stream+ :: Output stream to write 7zip archive. <tt>stream.write</tt> is needed.
165
197
  # +file+ :: File to be added to the 7zip archive. <b><tt>file</tt></b> must be a <b>relative path</b>.
166
- # +param+ :: Optional hash parameter. <tt>:password</tt> key represents password of this archive.
198
+ # +param+ :: Optional hash parameter.
199
+ # <tt>:password</tt> key specifies password of this archive.
200
+ # <tt>:sfx</tt> key specifies Self Extracting mode. <tt>:gui</tt> and <tt>:console</tt> can be used. <tt>true</tt> is same as <tt>:gui</tt>.
167
201
  #
168
202
  # ==== Examples
169
203
  # # Create 7zip archive which includes 'file.txt'.
@@ -171,9 +205,11 @@ module SevenZipRuby
171
205
  # SevenZipRuby::SevenZipWriter.add_file(file, 'file.txt')
172
206
  # end
173
207
  def add_file(stream, filename, param = {})
174
- open_param = {
175
- password: param.delete(:password)
176
- }
208
+ param = param.clone
209
+ open_param = {}
210
+ OPEN_PARAM_LIST.each do |key|
211
+ open_param[key] = param.delete(key) if param.key?(key)
212
+ end
177
213
  self.open(stream, open_param) do |szw|
178
214
  szw.add_file(filename, param)
179
215
  end
@@ -186,7 +222,9 @@ module SevenZipRuby
186
222
  #
187
223
  # ==== Args
188
224
  # +stream+ :: Output stream to write 7zip archive. <tt>stream.write</tt> is needed.
189
- # +param+ :: Optional hash parameter. <tt>:password</tt> key represents password of this archive.
225
+ # +param+ :: Optional hash parameter.
226
+ # <tt>:password</tt> key specifies password of this archive.
227
+ # <tt>:sfx</tt> key specifies Self Extracting mode. <tt>:gui</tt> and <tt>:console</tt> can be used. <tt>true</tt> is same as <tt>:gui</tt>.
190
228
  #
191
229
  # ==== Examples
192
230
  # File.open("filename.7z", "wb") do |file|
@@ -197,16 +235,25 @@ module SevenZipRuby
197
235
  # szw.close
198
236
  # end
199
237
  def open(stream, param = {})
238
+ param = param.clone
239
+ param[:password] = param[:password].to_s if (param[:password])
200
240
  stream.set_encoding(Encoding::ASCII_8BIT)
241
+
242
+ add_sfx(stream, param[:sfx]) if param[:sfx]
243
+
201
244
  open_impl(stream, param)
202
245
  return self
203
246
  end
204
247
 
205
248
  # Open 7zip archive file to create.
206
249
  #
250
+ # <tt>close</tt> method must be called later.
251
+ #
207
252
  # ==== Args
208
253
  # +filename+ :: 7zip archive filename.
209
- # +param+ :: Optional hash parameter. <tt>:password</tt> key represents password of this archive.
254
+ # +param+ :: Optional hash parameter.
255
+ # <tt>:password</tt> key specifies password of this archive.
256
+ # <tt>:sfx</tt> key specifies Self Extracting mode. <tt>:gui</tt> and <tt>:console</tt> can be used. <tt>true</tt> is same as <tt>:gui</tt>.
210
257
  #
211
258
  # ==== Examples
212
259
  # szw = SevenZipRuby::SevenZipWriter.new
@@ -425,6 +472,17 @@ module SevenZipRuby
425
472
  end
426
473
  private :compress_proc
427
474
 
475
+ def add_sfx(stream, sfx)
476
+ sfx = :default if sfx == true
477
+ sfx_file = SFX_FILE_LIST[sfx]
478
+ raise ArgumentError.new("invalid option: :sfx") unless sfx_file
479
+
480
+ File.open(sfx_file, "rb") do |input|
481
+ IO.copy_stream(input, stream)
482
+ end
483
+ end
484
+ private :add_sfx
485
+
428
486
  COMPRESS_GUARD = Mutex.new # :nodoc:
429
487
  def synchronize # :nodoc:
430
488
  if (COMPRESS_GUARD)
@@ -1,3 +1,3 @@
1
1
  module SevenZipRuby
2
- VERSION = "1.2.4"
2
+ VERSION = "1.2.5"
3
3
  end
@@ -206,7 +206,7 @@ describe SevenZipRuby do
206
206
  example "invalid index" do
207
207
  File.open(SevenZipRubySpecHelper::SEVEN_ZIP_FILE, "rb") do |file|
208
208
  SevenZipRuby::SevenZipReader.open(file) do |szr|
209
- expect{ szr.extract_data(nil) }.to raise_error (ArgumentError)
209
+ expect{ szr.extract_data(nil) }.to raise_error(ArgumentError)
210
210
  end
211
211
  end
212
212
  end
@@ -214,18 +214,22 @@ describe SevenZipRuby do
214
214
  example "invalid index for entry" do
215
215
  File.open(SevenZipRubySpecHelper::SEVEN_ZIP_FILE, "rb") do |file|
216
216
  SevenZipRuby::SevenZipReader.open(file) do |szr|
217
- expect{ szr.entry("a") }.to raise_error
217
+ expect{ szr.entry("a") }.to raise_error(TypeError)
218
218
  end
219
219
  end
220
220
  end
221
221
 
222
222
  example "invalid password" do
223
223
  File.open(SevenZipRubySpecHelper::SEVEN_ZIP_PASSWORD_FILE, "rb") do |file|
224
- expect{ SevenZipRuby::Reader.open(file){ |szr| szr.extract_data(1) } }.to raise_error
224
+ expect{ SevenZipRuby::Reader.open(file){ |szr| szr.extract_data(1) } }.to raise_error(StandardError)
225
225
  end
226
226
 
227
227
  File.open(SevenZipRubySpecHelper::SEVEN_ZIP_PASSWORD_FILE, "rb") do |file|
228
- expect{ SevenZipRuby::Reader.open(file, password: "a"){ |szr| szr.extract_data(1) } }.to raise_error
228
+ expect{ SevenZipRuby::Reader.open(file, password: "a"){ |szr| szr.extract_data(1) } }.to raise_error(SevenZipRuby::InvalidArchive)
229
+ end
230
+
231
+ File.open(SevenZipRubySpecHelper::SEVEN_ZIP_PASSWORD_FILE, "rb") do |file|
232
+ expect{ SevenZipRuby::Reader.open(file, password: :InvalidType){ |szr| szr.extract_data(1) } }.to raise_error(SevenZipRuby::InvalidArchive)
229
233
  end
230
234
  end
231
235
 
@@ -299,8 +303,8 @@ describe SevenZipRuby do
299
303
  end
300
304
 
301
305
  example "clone and dup cannot be called." do
302
- expect{ SevenZipRuby::SevenZipReader.new.clone }.to raise_error
303
- expect{ SevenZipRuby::SevenZipReader.new.dup }.to raise_error
306
+ expect{ SevenZipRuby::SevenZipReader.new.clone }.to raise_error(NoMethodError)
307
+ expect{ SevenZipRuby::SevenZipReader.new.dup }.to raise_error(NoMethodError)
304
308
  end
305
309
 
306
310
  end
@@ -369,6 +373,70 @@ describe SevenZipRuby do
369
373
  end
370
374
  end
371
375
 
376
+ example "set password" do
377
+ sample_data = "Sample Data"
378
+ sample_password = "sample password"
379
+
380
+ output = StringIO.new("")
381
+ SevenZipRuby::SevenZipWriter.open(output, { password: sample_password }) do |szw|
382
+ szw.add_data(sample_data, "hoge.txt")
383
+ end
384
+
385
+ output.rewind
386
+ SevenZipRuby::SevenZipReader.open(output, { password: sample_password }) do |szr|
387
+ expect(szr.extract_data(0)).to eq sample_data
388
+ end
389
+
390
+ output.rewind
391
+ expect{
392
+ SevenZipRuby::SevenZipReader.open(output, { password: "invalid password" }) do |szr|
393
+ szr.extract_data(0)
394
+ end
395
+ }.to raise_error(SevenZipRuby::InvalidArchive)
396
+
397
+
398
+ output = StringIO.new("")
399
+ SevenZipRuby::SevenZipWriter.open(output, { password: sample_password.to_sym }) do |szw|
400
+ szw.add_data(sample_data, "hoge.txt")
401
+ end
402
+
403
+ output.rewind
404
+ SevenZipRuby::SevenZipReader.open(output, { password: sample_password }) do |szr|
405
+ expect(szr.extract_data(0)).to eq sample_data
406
+ end
407
+ end
408
+
409
+ example "create a sfx archive" do
410
+ time = Time.now
411
+
412
+ output = StringIO.new("")
413
+ SevenZipRuby::SevenZipWriter.open(output) do |szw|
414
+ szw.add_data("hogehoge", "hoge.txt", ctime: time, atime: time, mtime: time)
415
+ end
416
+
417
+ output1 = StringIO.new("")
418
+ SevenZipRuby::SevenZipWriter.open(output1, sfx: true) do |szw|
419
+ szw.add_data("hogehoge", "hoge.txt", ctime: time, atime: time, mtime: time)
420
+ end
421
+
422
+ output2 = StringIO.new("")
423
+ SevenZipRuby::SevenZipWriter.open(output2, sfx: :gui) do |szw|
424
+ szw.add_data("hogehoge", "hoge.txt", ctime: time, atime: time, mtime: time)
425
+ end
426
+
427
+ output3 = StringIO.new("")
428
+ SevenZipRuby::SevenZipWriter.open(output3, sfx: :console) do |szw|
429
+ szw.add_data("hogehoge", "hoge.txt", ctime: time, atime: time, mtime: time)
430
+ end
431
+
432
+ gui = File.open(SevenZipRuby::SevenZipWriter::SFX_FILE_LIST[:gui], "rb", &:read)
433
+ console = File.open(SevenZipRuby::SevenZipWriter::SFX_FILE_LIST[:console], "rb", &:read)
434
+
435
+ expect(output1.string).to eq gui + output.string
436
+ expect(output2.string).to eq gui + output.string
437
+ expect(output3.string).to eq console + output.string
438
+ end
439
+
372
440
  [ true, false ].each do |use_native_input_file_stream|
373
441
  example "add_directory: use_native_input_file_stream=#{use_native_input_file_stream}" do
374
442
  SevenZipRuby::SevenZipWriter.use_native_input_file_stream = use_native_input_file_stream
@@ -562,11 +630,11 @@ describe SevenZipRuby do
562
630
  end
563
631
 
564
632
  example "invalid method" do
565
- expect{ SevenZipRuby::SevenZipWriter.open(StringIO.new("")).method = "Unknown" }.to raise_error
633
+ expect{ SevenZipRuby::SevenZipWriter.open(StringIO.new("")).method = "Unknown" }.to raise_error(ArgumentError)
566
634
  end
567
635
 
568
636
  example "invalid level" do
569
- expect{ SevenZipRuby::SevenZipWriter.open(StringIO.new("")).level = 2 }.to raise_error
637
+ expect{ SevenZipRuby::SevenZipWriter.open(StringIO.new("")).level = 2 }.to raise_error(ArgumentError)
570
638
  end
571
639
 
572
640
  example "add_data/mkdir/compress/close before open" do
@@ -592,8 +660,8 @@ describe SevenZipRuby do
592
660
  end
593
661
 
594
662
  example "clone and dup cannot be called." do
595
- expect{ SevenZipRuby::SevenZipWriter.new.clone }.to raise_error
596
- expect{ SevenZipRuby::SevenZipWriter.new.dup }.to raise_error
663
+ expect{ SevenZipRuby::SevenZipWriter.new.clone }.to raise_error(NoMethodError)
664
+ expect{ SevenZipRuby::SevenZipWriter.new.dup }.to raise_error(NoMethodError)
597
665
  end
598
666
 
599
667
  if (false && RUBY_ENGINE == "ruby")
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seven_zip_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.2.5
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-09-22 00:00:00.000000000 Z
11
+ date: 2016-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: SevenZipRuby (seven_zip_ruby) is a ruby gem library to read and write
@@ -61,8 +61,8 @@ extensions:
61
61
  - ext/seven_zip_ruby/extconf.rb
62
62
  extra_rdoc_files: []
63
63
  files:
64
- - .gitignore
65
- - .travis.yml
64
+ - ".gitignore"
65
+ - ".travis.yml"
66
66
  - Gemfile
67
67
  - LICENSE.txt
68
68
  - README.md
@@ -780,7 +780,9 @@ files:
780
780
  - ext/seven_zip_ruby/win32/mutex.h
781
781
  - lib/seven_zip_ruby.rb
782
782
  - lib/seven_zip_ruby/7z.dll
783
+ - lib/seven_zip_ruby/7z.sfx
783
784
  - lib/seven_zip_ruby/7z64.dll
785
+ - lib/seven_zip_ruby/7zCon.sfx
784
786
  - lib/seven_zip_ruby/archive_info.rb
785
787
  - lib/seven_zip_ruby/entry_info.rb
786
788
  - lib/seven_zip_ruby/exception.rb
@@ -801,17 +803,17 @@ require_paths:
801
803
  - lib
802
804
  required_ruby_version: !ruby/object:Gem::Requirement
803
805
  requirements:
804
- - - '>='
806
+ - - ">="
805
807
  - !ruby/object:Gem::Version
806
808
  version: 2.0.0
807
809
  required_rubygems_version: !ruby/object:Gem::Requirement
808
810
  requirements:
809
- - - '>='
811
+ - - ">="
810
812
  - !ruby/object:Gem::Version
811
813
  version: '0'
812
814
  requirements: []
813
815
  rubyforge_project:
814
- rubygems_version: 2.0.14
816
+ rubygems_version: 2.6.8
815
817
  signing_key:
816
818
  specification_version: 4
817
819
  summary: This is a ruby gem library to read and write 7zip files.