seven_zip_ruby 1.0.0-x64-mingw32

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 333a9e5d4a3ba9d029a31097890385421b26ad6a
4
+ data.tar.gz: 88079675cb2082646fd404de167d8f81a4a02f28
5
+ SHA512:
6
+ metadata.gz: 679357fdb1bd67992b018e59f2da39aec1fce0cab80de6415a67fa7b4d3a6d5dd57792e3825b9c9319e05b14478f1024046b90c56e0b831fde6ec5d0b35895b6
7
+ data.tar.gz: 3562b6fc59348f8a8ed4808c6ca37e9b1aa40aa62544188dc31ee7c59d4552242289bbd5304f4a2b2c6875f91f006fd7d1cdf9257833baa7e39237c495c4cd4d
data/.gitignore ADDED
@@ -0,0 +1,25 @@
1
+ *.rbc
2
+ *.o
3
+ *.so
4
+ *.bundle
5
+ *.bak
6
+ mkmf.log
7
+ .bundle
8
+ .config
9
+ .yardoc
10
+ Gemfile.lock
11
+ InstalledFiles
12
+ _yardoc
13
+ coverage
14
+ doc/
15
+ lib/bundler/man
16
+ rdoc
17
+ spec/reports
18
+ test/tmp
19
+ test/version_tmp
20
+ tmp
21
+ XTAGS
22
+ ext/seven_zip_ruby/Makefile
23
+ ext/seven_zip_ruby/*.def
24
+ ext/seven_zip_ruby/*.pdb
25
+ ext/p7zip/makefile.machine
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - "2.0.0"
4
+ cache:
5
+ - apt
6
+ before_install:
7
+ - bundle install --path=vendor/bundle
8
+ - sudo apt-get install p7zip-full
9
+ install: bundle exec rake build_local
10
+ script: bundle exec rspec spec/seven_zip_ruby_spec.rb
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in seven_zip_ruby.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,39 @@
1
+ Copyright (c) 2013 Masamitsu MURASE
2
+
3
+ SevenZipRuby
4
+
5
+ The GNU LGPL + unRAR restriction means that you must follow both
6
+ GNU LGPL rules and unRAR restriction rules.
7
+
8
+ GNU LGPL information
9
+ --------------------
10
+
11
+ This library is free software; you can redistribute it and/or
12
+ modify it under the terms of the GNU Lesser General Public
13
+ License as published by the Free Software Foundation; either
14
+ version 2.1 of the License, or (at your option) any later version.
15
+
16
+ This library is distributed in the hope that it will be useful,
17
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19
+ Lesser General Public License for more details.
20
+
21
+ You can receive a copy of the GNU Lesser General Public License from
22
+ http://www.gnu.org/
23
+
24
+
25
+ unRAR restriction
26
+ -----------------
27
+
28
+ The decompression engine for RAR archives was developed using source
29
+ code of unRAR program.
30
+ All copyrights to original unRAR code are owned by Alexander Roshal.
31
+
32
+ The license for original unRAR code has the following restriction:
33
+
34
+ The unRAR sources cannot be used to re-create the RAR compression algorithm,
35
+ which is proprietary. Distribution of modified unRAR sources in separate form
36
+ or as a part of other software is permitted, provided that it is clearly
37
+ stated in the documentation and source comments that the code may
38
+ not be used to develop a RAR (WinRAR) compatible archiver.
39
+
data/README.md ADDED
@@ -0,0 +1,176 @@
1
+ # SevenZipRuby ![Logo](https://raw.github.com/masamitsu-murase/seven_zip_ruby/master/resources/seven_zip_ruby_logo.png)
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)
4
+
5
+ This is a Ruby gem library to handle [7-Zip](http://www.7-zip.org) archives.
6
+
7
+ This extension calls the native library, 7z.dll or 7z.so, internally and it is included in this gem.
8
+
9
+ ## Features
10
+ * Use official DLL, 7z.dll, internally.
11
+ * Support extracting data into memory.
12
+
13
+ ## Examples
14
+
15
+ **This is a beta version.**
16
+ The interfaces may be changed.
17
+
18
+ If you have any comments about interface API, let me know please.
19
+
20
+ ### Extract archive
21
+ ```ruby
22
+ File.open("filename.7z", "rb") do |file|
23
+ SevenZipRuby::Reader.open(file) do |szr|
24
+ szr.extract_all "path_to_dir"
25
+ end
26
+ end
27
+ ```
28
+
29
+ You can also use handy method.
30
+ ```ruby
31
+ File.open("filename.7z", "rb") do |file|
32
+ SevenZipRuby::Reader.extract_all(file, "path_to_dir")
33
+ end
34
+ ```
35
+
36
+ ### Show entries in archive
37
+ ```ruby
38
+ File.open("filename.7z", "rb") do |file|
39
+ SevenZipRuby::Reader.open(file) do |szr|
40
+ list = szr.entries
41
+ p list
42
+ # => [ "#<EntryInfo: 0, dir, dir/subdir>", "#<EntryInfo: 1, file, dir/file.txt>", ... ]
43
+ end
44
+ end
45
+ ```
46
+
47
+ ### Extract encrypted archive
48
+ ```ruby
49
+ File.open("filename.7z", "rb") do |file|
50
+ SevenZipRuby::Reader.open(file, { password: "Password String" }) do |szr|
51
+ szr.extract_all "path_to_dir"
52
+ end
53
+ end
54
+ ```
55
+ or
56
+ ```ruby
57
+ File.open("filename.7z", "rb") do |file|
58
+ SevenZipRuby::Reader.extract_all(file, "path_to_dir", { password: "Password String" })
59
+ end
60
+ ```
61
+
62
+
63
+ ### Verify archive
64
+ ```ruby
65
+ File.open("filename.7z", "rb") do |file|
66
+ SevenZipRuby::Reader.verify(file)
67
+ # => true/false
68
+ end
69
+ ```
70
+
71
+ ### Compress files
72
+ ```ruby
73
+ File.open("filename.7z", "wb") do |file|
74
+ SevenZipRuby::Writer.open(file) do |szr|
75
+ szr.add_directory("dir")
76
+ end
77
+ end
78
+ ```
79
+ or
80
+ ```ruby
81
+ File.open("filename.7z", "wb") do |file|
82
+ SevenZipRuby::Writer.add_directory(file, "dir")
83
+ end
84
+ ```
85
+
86
+ ## Supported platforms
87
+
88
+ * Windows
89
+ * Linux
90
+ * Mac OSX
91
+
92
+ ## More examples
93
+
94
+ ### Extract partially
95
+
96
+ Extract files whose size is less than 1024.
97
+
98
+ ```ruby
99
+ File.open("filename.7z", "rb") do |file|
100
+ SevenZipRuby::Reader.open(file) do |szr|
101
+ small_files = szr.entries.select{ |i| i.file? && i.size < 1024 }
102
+ szr.extract(small_files, "path_to_dir")
103
+ end
104
+ end
105
+ ```
106
+
107
+ ### Get data from archive
108
+
109
+ Extract data into memory.
110
+
111
+ ```ruby
112
+ data = nil
113
+ File.open("filename.7z", "rb") do |file|
114
+ SevenZipRuby::Reader.open(file) do |szr|
115
+ smallest_file = szr.entries.select(&:file?).min_by(&:size)
116
+ data = szr.extract_data(smallest_file)
117
+ end
118
+ end
119
+ p data
120
+ # => File content is shown.
121
+
122
+ ### Create archive manually
123
+
124
+ ```
125
+ File.open("filename.7z", "rb") do |file|
126
+ SevenZipRuby::Writer.open(file) do |szr|
127
+ szr.add_file "entry1.txt"
128
+ szr.mkdir "dir1"
129
+ szr.mkdir "dir2"
130
+
131
+ data = [0, 1, 2, 3, 4].pack("C*")
132
+ szr.add_data data, "entry2.txt"
133
+ end
134
+ end
135
+ ```
136
+
137
+ ### Set compression mode
138
+
139
+ 7zip supports LZMA, LZMA2, PPMD, BZIP2, DEFLATE and COPY.
140
+
141
+ ```ruby
142
+ # random data
143
+ data = 50000000.to_enum(:times).map{ rand(256) }.pack("C*")
144
+
145
+ a = StringIO.new("")
146
+ start = Time.now
147
+ SevenZipRuby::Writer.open(a) do |szr|
148
+ szr.method = "BZIP2" # Set compression method to "BZIP2"
149
+ szr.multi_thread = false # Disable multi-threading mode
150
+ szr.add_data(data, "test.bin")
151
+ end
152
+ p(Time.now - start)
153
+ # => 11.180934
154
+
155
+ a = StringIO.new("")
156
+ start = Time.now
157
+ SevenZipRuby::Writer.open(a) do |szr|
158
+ szr.method = "BZIP2" # Set compression method to "BZIP2"
159
+ szr.multi_thread = true # Enable multi-threading mode (default)
160
+ szr.add_data(data, "test.bin")
161
+ end
162
+ p(Time.now - start)
163
+ # => 3.607563 # Faster than single-threaded compression.
164
+ ```
165
+
166
+
167
+ ## TODO
168
+
169
+ * Support file attributes on Linux and Mac OSX.
170
+ * Support updating archive.
171
+ * Support extracting rar archive.
172
+
173
+
174
+ ## License
175
+ LGPL and unRAR license. Please refer to LICENSE.txt.
176
+
data/Rakefile ADDED
@@ -0,0 +1,47 @@
1
+ require "fileutils"
2
+ require "bundler/gem_tasks"
3
+
4
+ BINARY_FILES = [ "seven_zip_archive.so", "seven_zip_archive.bundle" ]
5
+ MAKE = (ENV["MAKE"] || ENV["make"] || (RUBY_PLATFORM.include?("mswin") ? "nmake" : "make"))
6
+
7
+ task :build_platform => [ :pre_platform, :build, :post_platform ]
8
+
9
+ task :pre_platform do
10
+ FileUtils.mv("seven_zip_ruby.gemspec", "seven_zip_ruby.gemspec.bak")
11
+ FileUtils.cp("resources/seven_zip_ruby.gemspec.platform", "seven_zip_ruby.gemspec")
12
+ end
13
+
14
+ task :post_platform do
15
+ FileUtils.mv("seven_zip_ruby.gemspec.bak", "seven_zip_ruby.gemspec")
16
+ end
17
+
18
+
19
+ task :build_local_all => [ :build_local_clean, :build_local ]
20
+ task :build_local => [ :build_binary, :copy_binary ]
21
+
22
+ task :build_local_clean do
23
+ Dir.chdir "ext/seven_zip_ruby" do
24
+ sh("#{MAKE} clean") if (File.exist?("Makefile"))
25
+ end
26
+
27
+ [ "ext/seven_zip_ruby", "lib/seven_zip_ruby" ].each do |dir|
28
+ FileUtils.rmtree(BINARY_FILES.map{ |i| "#{dir}/#{i}" })
29
+ end
30
+ end
31
+
32
+ task :build_binary do
33
+ Dir.chdir "ext/seven_zip_ruby" do
34
+ FileUtils.rmtree BINARY_FILES
35
+ sh "ruby extconf.rb"
36
+ sh "#{MAKE}"
37
+ end
38
+ end
39
+
40
+ task :copy_binary do
41
+ BINARY_FILES.each do |file|
42
+ src = File.join("ext", "seven_zip_ruby", file)
43
+ dest = File.join("lib", "seven_zip_ruby", file)
44
+ FileUtils.rmtree(dest) if (File.exist?(dest))
45
+ FileUtils.cp(src, dest) if (File.exist?(src))
46
+ end
47
+ end
@@ -0,0 +1,16 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require_relative("seven_zip_ruby/version")
4
+
5
+ Dir.chdir("#{__dir__}/seven_zip_ruby"){ require_relative("seven_zip_ruby/seven_zip_archive") }
6
+ raise "Failed to initialize SevenZipRuby" unless (defined?(SevenZipRuby::SevenZipReader))
7
+
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")
14
+
15
+ module SevenZipRuby
16
+ end
Binary file
Binary file
@@ -0,0 +1,21 @@
1
+ module SevenZipRuby
2
+ class ArchiveInfo
3
+ def initialize(method, solid, num_blocks, header_size, phy_size)
4
+ @method, @solid, @num_blocks, @header_size, @phy_size =
5
+ method, solid, num_blocks, header_size, phy_size
6
+ end
7
+
8
+ attr_reader :method, :num_blocks, :header_size, :phy_size
9
+
10
+ alias size phy_size
11
+ alias block_num num_blocks
12
+
13
+ def solid?
14
+ return @solid
15
+ end
16
+
17
+ def inspect
18
+ "#<ArchiveInfo: #{method}, #{size}byte>"
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,45 @@
1
+ require("pathname")
2
+
3
+ module SevenZipRuby
4
+ class EntryInfo
5
+ def initialize(index, path, method, dir, encrypted, anti, size, pack_size, ctime, atime, mtime, attrib, crc)
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
8
+ end
9
+
10
+ attr_reader :index, :path, :method, :size, :pack_size, :ctime, :atime, :mtime, :attrib, :crc
11
+ alias to_i index
12
+
13
+ def directory?
14
+ return @dir
15
+ end
16
+
17
+ def file?
18
+ return !(@dir)
19
+ end
20
+
21
+ def encrypted?
22
+ return @encrypted
23
+ end
24
+
25
+ def anti?
26
+ return @anti
27
+ end
28
+
29
+ def has_data?
30
+ return !(@dir || @anti)
31
+ end
32
+
33
+ def inspect
34
+ if (@anti)
35
+ type = "anti"
36
+ elsif (@dir)
37
+ type = "dir"
38
+ else
39
+ type = "file"
40
+ end
41
+ str = path.to_s.encode(Encoding::ASCII, invalid: :replace, undef: :replace, replace: "?")
42
+ return "#<EntryInfo: #{index}, #{type}, #{str}>"
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,7 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module SevenZipRuby
4
+ class InvalidOperation < StandardError
5
+ end
6
+ end
7
+
@@ -0,0 +1,180 @@
1
+ require("stringio")
2
+
3
+ module SevenZipRuby
4
+ class SevenZipReader
5
+ class << self
6
+ def open(*args, &block)
7
+ szr = self.new
8
+ szr.open(*args)
9
+ if (block)
10
+ block.call(szr)
11
+ szr.close
12
+ else
13
+ szr
14
+ end
15
+ end
16
+
17
+ def extract(stream, index, dir = ".", param = {})
18
+ password = { password: param.delete(:password) }
19
+ self.open(stream, password) do |szr|
20
+ szr.extract(index, dir, param)
21
+ end
22
+ end
23
+
24
+ def extract_all(stream, dir = ".", param = {})
25
+ password = { password: param.delete(:password) }
26
+ self.open(stream, password) do |szr|
27
+ szr.extract_all(dir, param)
28
+ end
29
+ end
30
+
31
+ def verify(*args)
32
+ szr = self.open(*args)
33
+ ret = szr.verify
34
+ szr.close
35
+ return ret
36
+ end
37
+ end
38
+
39
+ def open(stream, param = {})
40
+ param[:password] = param[:password].to_s if (param[:password])
41
+ stream.set_encoding(Encoding::ASCII_8BIT)
42
+ open_impl(stream, param)
43
+ return self
44
+ end
45
+
46
+
47
+ def file_proc(base_dir)
48
+ base_dir = base_dir.to_s
49
+ return Proc.new do |type, arg|
50
+ case(type)
51
+ when :stream
52
+ ret = nil
53
+ if (arg.anti?)
54
+ arg.path.rmtree if (arg.path.exist?)
55
+ elsif (arg.file?)
56
+ path = arg.path.expand_path(base_dir)
57
+ path.parent.mkpath
58
+ ret = File.open(path, "wb")
59
+ else
60
+ path = arg.path.expand_path(base_dir)
61
+ path.mkpath
62
+ set_file_attribute(path.to_s, arg.attrib) if (arg.attrib)
63
+ path.utime(arg.atime || path.atime, arg.mtime || path.mtime)
64
+ end
65
+ next ret
66
+
67
+ when :result
68
+ arg[:stream].close
69
+ unless (arg[:info].anti?)
70
+ path = arg[:info].path.expand_path(base_dir)
71
+ set_file_attribute(path.to_s, arg[:info].attrib) if (arg[:info].attrib)
72
+ path.utime(arg[:info].atime || path.atime, arg[:info].mtime || path.mtime)
73
+ end
74
+ end
75
+ end
76
+ end
77
+ private :file_proc
78
+
79
+ def data_proc(output, idx_prj)
80
+ return Proc.new do |type, arg|
81
+ case(type)
82
+ when :stream
83
+ ret = (arg.has_data? ? StringIO.new("".b) : nil)
84
+ unless (arg.has_data?)
85
+ output[idx_prj[arg.index]] = nil
86
+ end
87
+ next ret
88
+
89
+ when :result
90
+ arg[:stream].close
91
+ if (arg[:info].has_data?)
92
+ output[idx_prj[arg[:info].index]] = arg[:stream].string
93
+ end
94
+
95
+ end
96
+ end
97
+ end
98
+ private :data_proc
99
+
100
+
101
+ def test
102
+ begin
103
+ return test_all_impl(nil)
104
+ rescue
105
+ return false
106
+ end
107
+ end
108
+ alias verify test
109
+
110
+ def verify_detail
111
+ begin
112
+ return test_all_impl(true)
113
+ rescue
114
+ return nil
115
+ end
116
+ end
117
+
118
+ def extract(index, dir = ".")
119
+ path = File.expand_path(dir)
120
+ case(index)
121
+ when Symbol
122
+ raise SevenZipError.new("Argument error") unless (index == :all)
123
+ return extract_all(path)
124
+ when Array
125
+ index_list = index.map(&:to_i).sort.uniq
126
+ extract_files_impl(index_list, file_proc(path))
127
+ else
128
+ extract_impl(index.to_i, file_proc(path))
129
+ end
130
+ end
131
+
132
+ def extract_all(dir = ".")
133
+ extract_all_impl(file_proc(File.expand_path(dir)))
134
+ end
135
+
136
+ def extract_if(dir = ".", &block)
137
+ extract(entries.select(&block).map(&:index), dir)
138
+ end
139
+
140
+ def extract_data(index)
141
+ case(index)
142
+ when :all
143
+ idx_prj = Object.new
144
+ def idx_prj.[](index)
145
+ return index
146
+ end
147
+
148
+ ret = []
149
+ extract_all_impl(data_proc(ret, idx_prj))
150
+ return ret
151
+
152
+ when Array
153
+ index_list = index.map(&:to_i)
154
+ idx_prj = Hash[*(index_list.each_with_index.map{ |idx, i| [ idx, i ] }.flatten)]
155
+
156
+ ret = []
157
+ extract_files_impl(index_list, data_proc(ret, idx_prj))
158
+ return ret
159
+
160
+ else
161
+ index = index.to_i
162
+ item = entry(index)
163
+ return nil unless (item.has_data?)
164
+
165
+ idx_prj = Object.new
166
+ def idx_prj.[](index)
167
+ return 0
168
+ end
169
+
170
+ ret = []
171
+ extract_impl(index, data_proc(ret, idx_prj))
172
+ return ret[0]
173
+
174
+ end
175
+ end
176
+ end
177
+
178
+
179
+ Reader = SevenZipReader
180
+ end