seven_zip_ruby 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +21 -5
- data/README.md +30 -14
- data/Rakefile +9 -1
- data/ext/seven_zip_ruby/extconf.rb +29 -7
- data/ext/seven_zip_ruby/seven_zip_archive.cpp +33 -12
- data/ext/seven_zip_ruby/seven_zip_archive.h +7 -1
- data/lib/seven_zip_ruby.rb +18 -11
- data/lib/seven_zip_ruby/7z.sfx +0 -0
- data/lib/seven_zip_ruby/7zCon.sfx +0 -0
- data/lib/seven_zip_ruby/seven_zip_reader.rb +28 -10
- data/lib/seven_zip_ruby/seven_zip_writer.rb +71 -13
- data/lib/seven_zip_ruby/version.rb +1 -1
- data/seven_zip_ruby.gemspec +3 -3
- data/spec/seven_zip_ruby_spec.rb +89 -21
- metadata +20 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5825d6fc6003666a0e46c7f7d04b02166df43dedfcce9c1321c585bdb572aa83
|
4
|
+
data.tar.gz: a1c55155547c4f190d5265adb38306d433b620c15b7dfd503e995577560b3708
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 143dfc6e36e05dc5697b90129f135beb67752425564fa761d973d4635b10c62ec2719ad2daab5076afc85301dd365c0c0e8ed5b35e9fa4934d3bc8672816ba14
|
7
|
+
data.tar.gz: 164fb272a9179e26ac2d0ee1f56c189047254ccd85e93ffc6bd1f4f6e56b399611f8dd3d655d6e816a35fd09615803354b54f4dbffee3bdd6bf58dc3f841727f
|
data/.travis.yml
CHANGED
@@ -1,19 +1,35 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- "2.0
|
4
|
-
- "2.1
|
5
|
-
- "
|
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"
|
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
|
-
-
|
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
@@ -4,15 +4,18 @@
|
|
4
4
|
|
5
5
|
This is a Ruby gem library to extract/compress [7-Zip](http://www.7-zip.org) archives.
|
6
6
|
|
7
|
-
This extension calls the native library, 7z.dll or 7z.so, internally and
|
7
|
+
This extension calls the native library, 7z.dll or 7z.so, internally and these libraries are included in this gem.
|
8
8
|
|
9
9
|
## Features
|
10
|
-
*
|
11
|
-
*
|
10
|
+
* Uses official DLL, 7z.dll, internally.
|
11
|
+
* Supports extracting data into memory.
|
12
|
+
|
13
|
+
## Document
|
14
|
+
[RDoc](http://rubydoc.info/gems/seven_zip_ruby/frames) shows you the details.
|
12
15
|
|
13
16
|
## Examples
|
14
17
|
|
15
|
-
### Extract
|
18
|
+
### Extract archives
|
16
19
|
|
17
20
|
```ruby
|
18
21
|
File.open("filename.7z", "rb") do |file|
|
@@ -22,7 +25,7 @@ File.open("filename.7z", "rb") do |file|
|
|
22
25
|
end
|
23
26
|
```
|
24
27
|
|
25
|
-
You can also use
|
28
|
+
You can also use simpler method.
|
26
29
|
|
27
30
|
```ruby
|
28
31
|
File.open("filename.7z", "rb") do |file|
|
@@ -30,7 +33,7 @@ File.open("filename.7z", "rb") do |file|
|
|
30
33
|
end
|
31
34
|
```
|
32
35
|
|
33
|
-
### Show entries in archive
|
36
|
+
### Show the entries in the archive
|
34
37
|
|
35
38
|
```ruby
|
36
39
|
File.open("filename.7z", "rb") do |file|
|
@@ -42,7 +45,7 @@ File.open("filename.7z", "rb") do |file|
|
|
42
45
|
end
|
43
46
|
```
|
44
47
|
|
45
|
-
### Extract encrypted
|
48
|
+
### Extract encrypted archives
|
46
49
|
|
47
50
|
```ruby
|
48
51
|
File.open("filename.7z", "rb") do |file|
|
@@ -60,7 +63,7 @@ end
|
|
60
63
|
```
|
61
64
|
|
62
65
|
|
63
|
-
### Verify
|
66
|
+
### Verify archives
|
64
67
|
|
65
68
|
```ruby
|
66
69
|
File.open("filename.7z", "rb") do |file|
|
@@ -114,7 +117,7 @@ File.open("filename.7z", "rb") do |file|
|
|
114
117
|
end
|
115
118
|
```
|
116
119
|
|
117
|
-
### Get data from
|
120
|
+
### Get data from archives
|
118
121
|
|
119
122
|
Extract data into memory.
|
120
123
|
|
@@ -130,7 +133,7 @@ p data
|
|
130
133
|
# => File content is shown.
|
131
134
|
```
|
132
135
|
|
133
|
-
### Create archive manually
|
136
|
+
### Create an archive manually
|
134
137
|
|
135
138
|
```ruby
|
136
139
|
File.open("filename.7z", "rb") do |file|
|
@@ -145,6 +148,17 @@ File.open("filename.7z", "rb") do |file|
|
|
145
148
|
end
|
146
149
|
```
|
147
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
|
+
|
148
162
|
### Set compression mode
|
149
163
|
|
150
164
|
7zip supports LZMA, LZMA2, PPMD, BZIP2, DEFLATE and COPY.
|
@@ -178,8 +192,8 @@ p(Time.now - start)
|
|
178
192
|
## TODO
|
179
193
|
|
180
194
|
* Support file attributes on Linux and Mac OSX.
|
181
|
-
* Support
|
182
|
-
* Support
|
195
|
+
* Support update of an archive.
|
196
|
+
* Support extract of a rar archive.
|
183
197
|
|
184
198
|
|
185
199
|
## License
|
@@ -187,8 +201,10 @@ LGPL and unRAR license. Please refer to LICENSE.txt.
|
|
187
201
|
|
188
202
|
## Releases
|
189
203
|
|
204
|
+
* 1.2.*
|
205
|
+
- Fixed cosmetic bugs.
|
190
206
|
* 1.1.0
|
191
|
-
|
207
|
+
- Fixed a bug. Raises an exception when wrong password is specified.
|
192
208
|
* 1.0.0
|
193
|
-
Initial release.
|
209
|
+
- Initial release.
|
194
210
|
|
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
|
-
|
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
|
@@ -130,24 +141,35 @@ def main
|
|
130
141
|
if (RUBY_PLATFORM.include?("mswin"))
|
131
142
|
# mswin32
|
132
143
|
$LIBS = "oleaut32.lib"
|
133
|
-
$CPPFLAGS = "/I.. /EHsc /DNDEBUG /DUSE_WIN32_FILE_API #{base_flag} "
|
144
|
+
$CPPFLAGS = "/I.. /EHsc /DNDEBUG /DUSE_WIN32_FILE_API #{base_flag} #{$CPPFLAGS} "
|
134
145
|
elsif (RUBY_PLATFORM.include?("mingw"))
|
135
146
|
# MinGW
|
136
147
|
$LIBS = "-loleaut32 -static-libgcc -static-libstdc++"
|
137
148
|
|
138
|
-
cpp0x_flag = [ "", "-std=
|
139
|
-
|
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
|
|
143
|
-
$CPPFLAGS = "-I.. #{cpp0x_flag} -DNDEBUG -DUSE_WIN32_FILE_API #{base_flag} "
|
154
|
+
$CPPFLAGS = "-I.. #{cpp0x_flag} -DNDEBUG -DUSE_WIN32_FILE_API #{base_flag} #{$CPPFLAGS} "
|
144
155
|
else
|
145
|
-
|
146
|
-
|
156
|
+
removed_flags = [ /\-mmacosx\-version\-min=[.0-9]+\b/ ]
|
157
|
+
removed_flags.each do |flag|
|
158
|
+
begin
|
159
|
+
$CFLAGS[flag] = ""
|
160
|
+
rescue
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
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)
|
147
169
|
end
|
148
170
|
raise "C++11 is not supported by the compiler." unless (cpp0x_flag)
|
149
171
|
|
150
|
-
$CPPFLAGS = "-I.. -I../CPP/include_windows -I../CPP #{cpp0x_flag} -DNDEBUG #{base_flag} "
|
172
|
+
$CPPFLAGS = "-I.. -I../CPP/include_windows -I../CPP #{cpp0x_flag} -DNDEBUG #{base_flag} #{$CPPFLAGS} "
|
151
173
|
|
152
174
|
|
153
175
|
ostype = check_ostype
|
@@ -2,6 +2,7 @@
|
|
2
2
|
#include <array>
|
3
3
|
#include <vector>
|
4
4
|
#include <cassert>
|
5
|
+
#include <string>
|
5
6
|
|
6
7
|
#ifndef _WIN32
|
7
8
|
#include <dlfcn.h>
|
@@ -13,6 +14,10 @@
|
|
13
14
|
|
14
15
|
#define INTERN(const_str) rb_intern2(const_str, sizeof(const_str) - 1)
|
15
16
|
|
17
|
+
// For https://bugs.ruby-lang.org/issues/11962
|
18
|
+
#ifndef RARRAY_CONST_PTR
|
19
|
+
#define RARRAY_CONST_PTR(index_list) RARRAY_PTR(index_list)
|
20
|
+
#endif
|
16
21
|
|
17
22
|
////////////////////////////////////////////////////////////////
|
18
23
|
namespace SevenZip
|
@@ -505,7 +510,7 @@ VALUE ArchiveReader::extractFiles(VALUE index_list, VALUE callback_proc)
|
|
505
510
|
fillEntryInfo();
|
506
511
|
|
507
512
|
std::vector<UInt32> list(RARRAY_LEN(index_list));
|
508
|
-
std::transform(
|
513
|
+
std::transform(RARRAY_CONST_PTR(index_list), RARRAY_CONST_PTR(index_list) + RARRAY_LEN(index_list),
|
509
514
|
list.begin(), [](VALUE num){ return NUM2ULONG(num); });
|
510
515
|
|
511
516
|
HRESULT ret;
|
@@ -1220,14 +1225,13 @@ STDMETHODIMP ArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStrea
|
|
1220
1225
|
bool ret = m_archive->runRubyAction([&](){
|
1221
1226
|
rb_stream = rb_funcall(proc, INTERN("call"), 2,
|
1222
1227
|
ID2SYM(INTERN("stream")), m_archive->entryInfo(index));
|
1228
|
+
m_archive->setProcessingStream(rb_stream, index, askExtractMode);
|
1223
1229
|
});
|
1224
1230
|
if (!ret){
|
1225
1231
|
m_archive->clearProcessingStream();
|
1226
1232
|
return E_FAIL;
|
1227
1233
|
}
|
1228
1234
|
|
1229
|
-
m_archive->setProcessingStream(rb_stream, index, askExtractMode);
|
1230
|
-
|
1231
1235
|
OutStream *stream = new OutStream(rb_stream, m_archive);
|
1232
1236
|
CMyComPtr<OutStream> ptr(stream);
|
1233
1237
|
*outStream = ptr.Detach();
|
@@ -1434,14 +1438,14 @@ STDMETHODIMP ArchiveUpdateCallback::GetStream(UInt32 index, ISequentialInStream
|
|
1434
1438
|
}else{
|
1435
1439
|
rb_stream = rb_ary_entry(ret_array, 1);
|
1436
1440
|
}
|
1441
|
+
|
1442
|
+
m_archive->setProcessingStream(rb_stream, index);
|
1437
1443
|
});
|
1438
1444
|
if (!ret){
|
1439
1445
|
m_archive->clearProcessingStream();
|
1440
1446
|
return E_FAIL;
|
1441
1447
|
}
|
1442
1448
|
|
1443
|
-
m_archive->setProcessingStream(rb_stream, index);
|
1444
|
-
|
1445
1449
|
if (NIL_P(rb_stream) && !(filepath.empty())){
|
1446
1450
|
FileInStream *stream = new FileInStream(filepath, m_archive);
|
1447
1451
|
CMyComPtr<FileInStream> ptr(stream);
|
@@ -1533,7 +1537,7 @@ STDMETHODIMP InStream::Read(void *data, UInt32 size, UInt32 *processedSize)
|
|
1533
1537
|
bool ret = m_archive->runRubyAction([&](){
|
1534
1538
|
VALUE str = rb_funcall(m_stream, INTERN("read"), 1, ULONG2NUM(size));
|
1535
1539
|
if (!NIL_P(str) && data){
|
1536
|
-
|
1540
|
+
memcpy(data, RSTRING_PTR(str), RSTRING_LEN(str));
|
1537
1541
|
}
|
1538
1542
|
|
1539
1543
|
if (processedSize){
|
@@ -1763,13 +1767,33 @@ extern "C" void Init_seven_zip_archive(void)
|
|
1763
1767
|
using namespace SevenZip;
|
1764
1768
|
using namespace RubyCppUtil;
|
1765
1769
|
|
1770
|
+
VALUE mod = rb_define_module("SevenZipRuby");
|
1771
|
+
gSevenZipModule = mod;
|
1772
|
+
|
1773
|
+
VALUE external_lib_dir = rb_const_get(mod, INTERN("EXTERNAL_LIB_DIR"));
|
1774
|
+
std::string external_lib_dir_str(RSTRING_PTR(external_lib_dir), RSTRING_LEN(external_lib_dir));
|
1775
|
+
|
1766
1776
|
#ifdef _WIN32
|
1767
|
-
|
1777
|
+
const int len = MultiByteToWideChar(CP_UTF8, 0, external_lib_dir_str.c_str(), external_lib_dir_str.length(),
|
1778
|
+
NULL, 0);
|
1779
|
+
if (len == 0) {
|
1780
|
+
rb_warning("MultiByteToWideChar error.");
|
1781
|
+
return;
|
1782
|
+
}
|
1783
|
+
std::vector<wchar_t> external_lib_dir_vec(len);
|
1784
|
+
MultiByteToWideChar(CP_UTF8, 0, external_lib_dir_str.c_str(), external_lib_dir_str.length(),
|
1785
|
+
&external_lib_dir_vec[0], external_lib_dir_vec.size());
|
1786
|
+
const std::wstring external_lib_dir_wstr(&external_lib_dir_vec[0], len);
|
1787
|
+
|
1788
|
+
const std::wstring dll_path = external_lib_dir_wstr + L"/7z.dll";
|
1789
|
+
gSevenZipHandle = LoadLibraryW(dll_path.c_str());
|
1768
1790
|
if (!gSevenZipHandle){
|
1769
|
-
|
1791
|
+
const std::wstring dll_path2 = external_lib_dir_wstr + L"/7z64.dll";
|
1792
|
+
gSevenZipHandle = LoadLibraryW(dll_path2.c_str());
|
1770
1793
|
}
|
1771
1794
|
#else
|
1772
|
-
|
1795
|
+
std::string dll_path = external_lib_dir_str + "/7z.so";
|
1796
|
+
gSevenZipHandle = dlopen(dll_path.c_str(), RTLD_NOW);
|
1773
1797
|
#endif
|
1774
1798
|
if (!gSevenZipHandle){
|
1775
1799
|
rb_warning("7z library is not found.");
|
@@ -1787,9 +1811,6 @@ extern "C" void Init_seven_zip_archive(void)
|
|
1787
1811
|
}
|
1788
1812
|
|
1789
1813
|
|
1790
|
-
VALUE mod = rb_define_module("SevenZipRuby");
|
1791
|
-
gSevenZipModule = mod;
|
1792
|
-
|
1793
1814
|
VALUE cls;
|
1794
1815
|
|
1795
1816
|
// arg_count is needed by MSVC 2010...
|
@@ -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
|
|
data/lib/seven_zip_ruby.rb
CHANGED
@@ -2,19 +2,26 @@
|
|
2
2
|
|
3
3
|
require("seven_zip_ruby/version")
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
module SevenZipRuby
|
6
|
+
def self.find_external_lib_dir
|
7
|
+
external_lib = (RUBY_PLATFORM.downcase.match(/mswin|mingw/) ? "7z.dll" : "7z.so")
|
8
|
+
dir = $LOAD_PATH.find do |i|
|
9
|
+
path = File.expand_path(File.join(i, "seven_zip_ruby", external_lib))
|
10
|
+
next File.file?(path)
|
11
|
+
end
|
12
|
+
raise "Failed to find 7z.dll or 7z.so" unless dir
|
10
13
|
|
11
|
-
|
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")
|
14
|
+
return File.join(dir, "seven_zip_ruby")
|
17
15
|
end
|
16
|
+
|
17
|
+
EXTERNAL_LIB_DIR = self.find_external_lib_dir.encode(Encoding::UTF_8)
|
18
|
+
end
|
19
|
+
|
20
|
+
begin
|
21
|
+
version = RUBY_VERSION.match(/\d+\.\d+/)
|
22
|
+
require("seven_zip_ruby/#{version}/seven_zip_archive")
|
23
|
+
rescue LoadError
|
24
|
+
require("seven_zip_ruby/seven_zip_archive")
|
18
25
|
end
|
19
26
|
raise "Failed to initialize SevenZipRuby" unless (defined?(SevenZipRuby::SevenZipReader))
|
20
27
|
|
Binary file
|
Binary file
|
@@ -102,8 +102,12 @@ module SevenZipRuby
|
|
102
102
|
szr = self.new
|
103
103
|
szr.open(stream, param)
|
104
104
|
if (block)
|
105
|
-
|
106
|
-
|
105
|
+
begin
|
106
|
+
block.call(szr)
|
107
|
+
szr.close
|
108
|
+
ensure
|
109
|
+
szr.close_file
|
110
|
+
end
|
107
111
|
else
|
108
112
|
szr
|
109
113
|
end
|
@@ -135,8 +139,12 @@ module SevenZipRuby
|
|
135
139
|
szr = self.new
|
136
140
|
szr.open_file(filename, param)
|
137
141
|
if (block)
|
138
|
-
|
139
|
-
|
142
|
+
begin
|
143
|
+
block.call(szr)
|
144
|
+
szr.close
|
145
|
+
ensure
|
146
|
+
szr.close_file
|
147
|
+
end
|
140
148
|
else
|
141
149
|
szr
|
142
150
|
end
|
@@ -200,9 +208,14 @@ module SevenZipRuby
|
|
200
208
|
# # => true/false
|
201
209
|
# end
|
202
210
|
def verify(stream, opt = {})
|
203
|
-
|
204
|
-
|
205
|
-
|
211
|
+
ret = false
|
212
|
+
begin
|
213
|
+
self.open(stream, opt) do |szr|
|
214
|
+
ret = szr.verify
|
215
|
+
end
|
216
|
+
rescue
|
217
|
+
ret = false
|
218
|
+
end
|
206
219
|
return ret
|
207
220
|
end
|
208
221
|
end
|
@@ -223,6 +236,7 @@ module SevenZipRuby
|
|
223
236
|
# szr.close
|
224
237
|
# end
|
225
238
|
def open(stream, param = {})
|
239
|
+
param = param.clone
|
226
240
|
param[:password] = param[:password].to_s if (param[:password])
|
227
241
|
stream.set_encoding(Encoding::ASCII_8BIT)
|
228
242
|
open_impl(stream, param)
|
@@ -248,8 +262,12 @@ module SevenZipRuby
|
|
248
262
|
|
249
263
|
def close
|
250
264
|
close_impl
|
265
|
+
close_file
|
266
|
+
end
|
267
|
+
|
268
|
+
def close_file # :nodoc:
|
251
269
|
if (@stream)
|
252
|
-
@stream.close
|
270
|
+
@stream.close rescue nil
|
253
271
|
@stream = nil
|
254
272
|
end
|
255
273
|
end
|
@@ -459,7 +477,7 @@ module SevenZipRuby
|
|
459
477
|
path = arg_path.expand_path(base_dir)
|
460
478
|
path.mkpath
|
461
479
|
set_file_attribute(path.to_s, arg.attrib) if (arg.attrib)
|
462
|
-
path.utime(arg.atime || path.atime, arg.mtime || path.mtime)
|
480
|
+
path.utime(arg.atime || path.atime, arg.mtime || path.mtime) rescue nil
|
463
481
|
end
|
464
482
|
next ret
|
465
483
|
|
@@ -470,7 +488,7 @@ module SevenZipRuby
|
|
470
488
|
unless (arg[:info].anti?)
|
471
489
|
path = Pathname(arg[:info].path).expand_path(base_dir)
|
472
490
|
set_file_attribute(path.to_s, arg[:info].attrib) if (arg[:info].attrib)
|
473
|
-
path.utime(arg[:info].atime || path.atime, arg[:info].mtime || path.mtime)
|
491
|
+
path.utime(arg[:info].atime || path.atime, arg[:info].mtime || path.mtime) rescue nil
|
474
492
|
end
|
475
493
|
end
|
476
494
|
end
|
@@ -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.
|
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.
|
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.
|
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
|
-
|
153
|
-
|
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.
|
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
|
-
|
175
|
-
|
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.
|
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.
|
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)
|
data/seven_zip_ruby.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = SevenZipRuby::VERSION
|
9
9
|
spec.authors = ["Masamitsu MURASE"]
|
10
10
|
spec.email = ["masamitsu.murase@gmail.com"]
|
11
|
-
spec.description = %q{SevenZipRuby is a gem library to read and write 7zip archives. This gem library calls official 7z.dll internally.}
|
12
|
-
spec.summary = %q{This is a gem library to read and write
|
11
|
+
spec.description = %q{SevenZipRuby (seven_zip_ruby) is a ruby gem library to read and write 7zip archives. This gem library calls official 7z.dll internally.}
|
12
|
+
spec.summary = %q{This is a ruby gem library to read and write 7zip files.}
|
13
13
|
spec.homepage = "https://github.com/masamitsu-murase/seven_zip_ruby"
|
14
14
|
spec.license = "LGPL + unRAR"
|
15
15
|
|
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.required_ruby_version = '>= 2.0.0'
|
22
22
|
|
23
|
-
spec.add_development_dependency "bundler"
|
23
|
+
spec.add_development_dependency "bundler"
|
24
24
|
spec.add_development_dependency "rake"
|
25
25
|
spec.add_development_dependency "rspec"
|
26
26
|
if (RUBY_ENGINE == "rbx")
|
data/spec/seven_zip_ruby_spec.rb
CHANGED
@@ -54,7 +54,7 @@ describe SevenZipRuby do
|
|
54
54
|
expect(info.header_size).to be < file.size
|
55
55
|
expect(info.method).to eq "LZMA"
|
56
56
|
expect(info.phy_size).to be file.size
|
57
|
-
expect(info.solid?).to
|
57
|
+
expect(info.solid?).to be true
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
@@ -139,6 +139,11 @@ describe SevenZipRuby do
|
|
139
139
|
|
140
140
|
expect(SevenZipRuby::SevenZipReader.verify(StringIO.new(data))).to eq true
|
141
141
|
|
142
|
+
data_org = data[-1]
|
143
|
+
data[-1] = 0x01.chr # This highly dependes on the current test binary.
|
144
|
+
expect(SevenZipRuby::SevenZipReader.verify(StringIO.new(data))).to eq false
|
145
|
+
data[-1] = data_org
|
146
|
+
|
142
147
|
data[0x27] = 0xEB.chr # This highly dependes on the current test binary.
|
143
148
|
expected = [ :DataError, :DataError, :DataError, :DataError, :DataError, :DataError, :DataError, true, true, true, true, true ]
|
144
149
|
SevenZipRuby::SevenZipReader.open(StringIO.new(data)) do |szr|
|
@@ -179,9 +184,7 @@ describe SevenZipRuby do
|
|
179
184
|
end
|
180
185
|
th_list.push(th)
|
181
186
|
end
|
182
|
-
th_list.each
|
183
|
-
t.join
|
184
|
-
end
|
187
|
+
th_list.each(&:join)
|
185
188
|
end
|
186
189
|
|
187
190
|
|
@@ -203,7 +206,7 @@ describe SevenZipRuby do
|
|
203
206
|
example "invalid index" do
|
204
207
|
File.open(SevenZipRubySpecHelper::SEVEN_ZIP_FILE, "rb") do |file|
|
205
208
|
SevenZipRuby::SevenZipReader.open(file) do |szr|
|
206
|
-
expect{ szr.extract_data(nil) }.to raise_error
|
209
|
+
expect{ szr.extract_data(nil) }.to raise_error(ArgumentError)
|
207
210
|
end
|
208
211
|
end
|
209
212
|
end
|
@@ -211,18 +214,22 @@ describe SevenZipRuby do
|
|
211
214
|
example "invalid index for entry" do
|
212
215
|
File.open(SevenZipRubySpecHelper::SEVEN_ZIP_FILE, "rb") do |file|
|
213
216
|
SevenZipRuby::SevenZipReader.open(file) do |szr|
|
214
|
-
expect{ szr.entry("a") }.to raise_error
|
217
|
+
expect{ szr.entry("a") }.to raise_error(TypeError)
|
215
218
|
end
|
216
219
|
end
|
217
220
|
end
|
218
221
|
|
219
222
|
example "invalid password" do
|
220
223
|
File.open(SevenZipRubySpecHelper::SEVEN_ZIP_PASSWORD_FILE, "rb") do |file|
|
221
|
-
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
|
+
end
|
226
|
+
|
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(SevenZipRuby::InvalidArchive)
|
222
229
|
end
|
223
230
|
|
224
231
|
File.open(SevenZipRubySpecHelper::SEVEN_ZIP_PASSWORD_FILE, "rb") do |file|
|
225
|
-
expect{ SevenZipRuby::Reader.open(file, password:
|
232
|
+
expect{ SevenZipRuby::Reader.open(file, password: :InvalidType){ |szr| szr.extract_data(1) } }.to raise_error(SevenZipRuby::InvalidArchive)
|
226
233
|
end
|
227
234
|
end
|
228
235
|
|
@@ -296,8 +303,8 @@ describe SevenZipRuby do
|
|
296
303
|
end
|
297
304
|
|
298
305
|
example "clone and dup cannot be called." do
|
299
|
-
expect{ SevenZipRuby::SevenZipReader.new.clone }.to raise_error
|
300
|
-
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)
|
301
308
|
end
|
302
309
|
|
303
310
|
end
|
@@ -366,6 +373,70 @@ describe SevenZipRuby do
|
|
366
373
|
end
|
367
374
|
end
|
368
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
|
+
|
369
440
|
[ true, false ].each do |use_native_input_file_stream|
|
370
441
|
example "add_directory: use_native_input_file_stream=#{use_native_input_file_stream}" do
|
371
442
|
SevenZipRuby::SevenZipWriter.use_native_input_file_stream = use_native_input_file_stream
|
@@ -512,7 +583,6 @@ describe SevenZipRuby do
|
|
512
583
|
|
513
584
|
example "run in multi threads" do
|
514
585
|
th_list = []
|
515
|
-
mutex = Mutex.new
|
516
586
|
100.times do
|
517
587
|
th = Thread.new do
|
518
588
|
stream = StringIO.new
|
@@ -523,9 +593,7 @@ describe SevenZipRuby do
|
|
523
593
|
end
|
524
594
|
th_list.push(th)
|
525
595
|
end
|
526
|
-
th_list.each
|
527
|
-
t.join
|
528
|
-
end
|
596
|
+
th_list.each(&:join)
|
529
597
|
end
|
530
598
|
|
531
599
|
if (SevenZipRubySpecHelper.processor_count && SevenZipRubySpecHelper.processor_count > 1)
|
@@ -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")
|
@@ -616,11 +684,11 @@ describe SevenZipRuby do
|
|
616
684
|
th.join
|
617
685
|
diff = Time.now - start
|
618
686
|
|
619
|
-
|
687
|
+
20.times do
|
688
|
+
kill_time = rand * diff
|
620
689
|
th = Thread.start{ prc.call }
|
621
|
-
sleep(
|
690
|
+
sleep(kill_time)
|
622
691
|
expect{ th.kill }.not_to raise_error # Thread can be killed.
|
623
|
-
sleep diff*2 # Workaround. When some threads of SZR are running and killed, SEGV sometimes occurs...
|
624
692
|
end
|
625
693
|
end
|
626
694
|
end
|
metadata
CHANGED
@@ -1,59 +1,59 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seven_zip_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masamitsu MURASE
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-08-11 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
|
-
version: '
|
19
|
+
version: '0'
|
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
|
-
version: '
|
26
|
+
version: '0'
|
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
|
-
description: SevenZipRuby is a gem library to read and write
|
56
|
-
library calls official 7z.dll internally.
|
55
|
+
description: SevenZipRuby (seven_zip_ruby) is a ruby gem library to read and write
|
56
|
+
7zip archives. This gem library calls official 7z.dll internally.
|
57
57
|
email:
|
58
58
|
- masamitsu.murase@gmail.com
|
59
59
|
executables: []
|
@@ -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,20 +803,19 @@ 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
|
-
|
814
|
-
rubygems_version: 2.0.2
|
815
|
+
rubygems_version: 3.1.2
|
815
816
|
signing_key:
|
816
817
|
specification_version: 4
|
817
|
-
summary: This is a gem library to read and write
|
818
|
+
summary: This is a ruby gem library to read and write 7zip files.
|
818
819
|
test_files:
|
819
820
|
- spec/seven_zip_ruby_spec.rb
|
820
821
|
- spec/seven_zip_ruby_spec_helper.rb
|