omnizip 0.3.13 → 0.3.14
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 +4 -4
- data/lib/omnizip/algorithm.rb +36 -1
- data/lib/omnizip/algorithms/bzip2.rb +1 -3
- data/lib/omnizip/algorithms/deflate.rb +1 -3
- data/lib/omnizip/algorithms/deflate64.rb +2 -2
- data/lib/omnizip/algorithms/lzma.rb +1 -1
- data/lib/omnizip/algorithms/lzma2.rb +4 -12
- data/lib/omnizip/algorithms/zstandard.rb +1 -3
- data/lib/omnizip/algorithms.rb +14 -1
- data/lib/omnizip/commands/archive_list_command.rb +9 -7
- data/lib/omnizip/entry.rb +44 -0
- data/lib/omnizip/extraction/selective_extractor.rb +2 -10
- data/lib/omnizip/filter_pipeline.rb +1 -1
- data/lib/omnizip/filter_registry.rb +18 -16
- data/lib/omnizip/filters/bcj2.rb +1 -1
- data/lib/omnizip/filters/bcj_arm.rb +1 -1
- data/lib/omnizip/filters/bcj_arm64.rb +1 -1
- data/lib/omnizip/filters/bcj_ia64.rb +1 -1
- data/lib/omnizip/filters/bcj_ppc.rb +1 -1
- data/lib/omnizip/filters/bcj_sparc.rb +1 -1
- data/lib/omnizip/filters/bcj_x86.rb +1 -1
- data/lib/omnizip/filters.rb +0 -2
- data/lib/omnizip/formats/bzip2_file.rb +0 -7
- data/lib/omnizip/formats/cpio/entry.rb +6 -0
- data/lib/omnizip/formats/cpio.rb +0 -6
- data/lib/omnizip/formats/gzip.rb +0 -7
- data/lib/omnizip/formats/iso/directory_record.rb +7 -0
- data/lib/omnizip/formats/iso.rb +0 -5
- data/lib/omnizip/formats/lzip.rb +0 -7
- data/lib/omnizip/formats/lzma_alone.rb +0 -6
- data/lib/omnizip/formats/msi/entry.rb +6 -0
- data/lib/omnizip/formats/msi.rb +0 -9
- data/lib/omnizip/formats/ole/dirent.rb +6 -0
- data/lib/omnizip/formats/ole.rb +0 -9
- data/lib/omnizip/formats/rar.rb +0 -6
- data/lib/omnizip/formats/rar3/reader.rb +7 -0
- data/lib/omnizip/formats/rar5/reader.rb +7 -0
- data/lib/omnizip/formats/rpm/entry.rb +6 -0
- data/lib/omnizip/formats/seven_zip/models/file_entry.rb +7 -0
- data/lib/omnizip/formats/seven_zip.rb +0 -6
- data/lib/omnizip/formats/tar/entry.rb +6 -0
- data/lib/omnizip/formats/tar.rb +0 -6
- data/lib/omnizip/formats/xar/entry.rb +6 -0
- data/lib/omnizip/formats/xar.rb +0 -6
- data/lib/omnizip/formats/zip.rb +0 -6
- data/lib/omnizip/implementations.rb +18 -4
- data/lib/omnizip/metadata/entry_metadata.rb +7 -0
- data/lib/omnizip/parallel/engine.rb +48 -0
- data/lib/omnizip/parallel/parallel_compressor.rb +5 -16
- data/lib/omnizip/parallel/parallel_extractor.rb +5 -16
- data/lib/omnizip/parallel.rb +1 -0
- data/lib/omnizip/registry.rb +0 -1
- data/lib/omnizip/rubyzip_compat.rb +0 -1
- data/lib/omnizip/version.rb +1 -1
- data/lib/omnizip/zip/entry.rb +7 -0
- data/lib/omnizip.rb +1 -1
- metadata +4 -6
- data/lib/omnizip/filters/filter_base.rb +0 -6
- data/lib/omnizip/filters/registration.rb +0 -22
- data/lib/omnizip/filters/registry.rb +0 -111
- data/lib/omnizip/format_registry.rb +0 -100
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3d76166f4e6d65cb67526c079369395377bc4d30af75d52b9d83374f99721071
|
|
4
|
+
data.tar.gz: c47f5c274906ca6d92293606add01a44bfdb4e3f2f499647608bd2ac0629b98f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4cc7cbf7d9ce6763e6648abc3415b588a5a79df8e6b15fdfea5a6db962531b7c584628c1fe1b2c5c604d4113d05f9120bd8eb61a1fba70acdbfa324b3e621a2f
|
|
7
|
+
data.tar.gz: b796a58122e8d1b9ce208aafbf2b64826789e34fd8d165f05bab54ebd74b9169bdb1814bb8f83f2209bc09abad465a5b5b73c12be8570e3b2429a3288119563f
|
data/lib/omnizip/algorithm.rb
CHANGED
|
@@ -23,6 +23,8 @@ module Omnizip
|
|
|
23
23
|
# the required methods. Algorithms are automatically registered with the
|
|
24
24
|
# AlgorithmRegistry when defined.
|
|
25
25
|
class Algorithm
|
|
26
|
+
require "stringio"
|
|
27
|
+
|
|
26
28
|
attr_reader :options, :filter
|
|
27
29
|
|
|
28
30
|
# Initialize algorithm with options.
|
|
@@ -38,7 +40,7 @@ module Omnizip
|
|
|
38
40
|
# The filter will be applied before compression and reversed after
|
|
39
41
|
# decompression. Returns self for method chaining.
|
|
40
42
|
#
|
|
41
|
-
# @param filter [
|
|
43
|
+
# @param filter [Omnizip::Filter, FilterPipeline] Filter or
|
|
42
44
|
# pipeline to use
|
|
43
45
|
# @return [self] For method chaining
|
|
44
46
|
def with_filter(filter)
|
|
@@ -82,6 +84,39 @@ module Omnizip
|
|
|
82
84
|
"#{self} must implement .metadata"
|
|
83
85
|
end
|
|
84
86
|
|
|
87
|
+
# Class-level convenience: compress `data` and return the
|
|
88
|
+
# compressed bytes. Carries the algorithm's streaming contract
|
|
89
|
+
# over a single StringIO so callers with the whole payload in
|
|
90
|
+
# memory (parallel compressors, small files) don't need to
|
|
91
|
+
# instantiate and wire streams themselves.
|
|
92
|
+
#
|
|
93
|
+
# @param data [String, IO] Input to compress
|
|
94
|
+
# @param options [Hash] Forwarded to the algorithm
|
|
95
|
+
# @return [String] Compressed bytes
|
|
96
|
+
def compress(data, **options)
|
|
97
|
+
instance = new(options)
|
|
98
|
+
input = data.is_a?(::IO) ? data : ::StringIO.new(data.to_s.b)
|
|
99
|
+
output = ::StringIO.new
|
|
100
|
+
output.set_encoding(Encoding::BINARY)
|
|
101
|
+
instance.compress(input, output, options)
|
|
102
|
+
output.string
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Class-level convenience: decompress `data` and return the
|
|
106
|
+
# uncompressed bytes. Mirror of +.compress+.
|
|
107
|
+
#
|
|
108
|
+
# @param data [String, IO] Input to decompress
|
|
109
|
+
# @param options [Hash] Forwarded to the algorithm
|
|
110
|
+
# @return [String] Decompressed bytes
|
|
111
|
+
def decompress(data, **options)
|
|
112
|
+
instance = new(options)
|
|
113
|
+
input = data.is_a?(::IO) ? data : ::StringIO.new(data.to_s.b)
|
|
114
|
+
output = ::StringIO.new
|
|
115
|
+
output.set_encoding(Encoding::BINARY)
|
|
116
|
+
instance.decompress(input, output, options)
|
|
117
|
+
output.string
|
|
118
|
+
end
|
|
119
|
+
|
|
85
120
|
# Automatically register algorithm when inherited.
|
|
86
121
|
#
|
|
87
122
|
# This hook is called whenever a class inherits from Algorithm,
|
|
@@ -82,9 +82,7 @@ module Omnizip
|
|
|
82
82
|
# @param options [Models::CompressionOptions] Decompression options
|
|
83
83
|
# @return [void]
|
|
84
84
|
def decompress(input_stream, output_stream, _options = nil)
|
|
85
|
-
|
|
86
|
-
output_stream.set_encoding(Encoding::BINARY)
|
|
87
|
-
end
|
|
85
|
+
output_stream.set_encoding(Encoding::BINARY)
|
|
88
86
|
decoder = Decoder.new(input_stream)
|
|
89
87
|
decompressed = decoder.decode_stream
|
|
90
88
|
output_stream.write(decompressed)
|
|
@@ -77,9 +77,7 @@ module Omnizip
|
|
|
77
77
|
# @param options [Models::CompressionOptions] Decompression options
|
|
78
78
|
# @return [void]
|
|
79
79
|
def decompress(input_stream, output_stream, _options = nil)
|
|
80
|
-
|
|
81
|
-
output_stream.set_encoding(Encoding::BINARY)
|
|
82
|
-
end
|
|
80
|
+
output_stream.set_encoding(Encoding::BINARY)
|
|
83
81
|
decoder = Decoder.new(input_stream)
|
|
84
82
|
decompressed = decoder.decode_stream
|
|
85
83
|
output_stream.write(decompressed)
|
|
@@ -73,8 +73,8 @@ module Omnizip
|
|
|
73
73
|
return if compressed.nil? || compressed.empty?
|
|
74
74
|
|
|
75
75
|
# Set output to binary mode if it's a StringIO
|
|
76
|
-
output.set_encoding(Encoding::BINARY)
|
|
77
|
-
output.binmode
|
|
76
|
+
output.set_encoding(Encoding::BINARY)
|
|
77
|
+
output.binmode
|
|
78
78
|
|
|
79
79
|
# Use Zlib::Inflate with maximum window size
|
|
80
80
|
inflater = Zlib::Inflate.new(Zlib::MAX_WBITS)
|
|
@@ -136,7 +136,7 @@ module Omnizip
|
|
|
136
136
|
# @return [IO] The output_stream (for chaining)
|
|
137
137
|
def decompress(input_stream, output_stream, options = nil)
|
|
138
138
|
# Set binary encoding on output stream for proper byte handling
|
|
139
|
-
output_stream.set_encoding(Encoding::BINARY)
|
|
139
|
+
output_stream.set_encoding(Encoding::BINARY)
|
|
140
140
|
|
|
141
141
|
# Build decoder options, merging with instance variables as fallbacks
|
|
142
142
|
decoder_opts = build_decoder_options(options)
|
|
@@ -83,23 +83,19 @@ module Omnizip
|
|
|
83
83
|
)
|
|
84
84
|
|
|
85
85
|
# Read input
|
|
86
|
-
input_data =
|
|
86
|
+
input_data = Omnizip::IO::Source.for(input).read
|
|
87
87
|
|
|
88
88
|
# Encode with LZMA2
|
|
89
89
|
compressed = encoder.encode(input_data)
|
|
90
90
|
|
|
91
91
|
# Write to output
|
|
92
|
-
|
|
93
|
-
output.write(compressed)
|
|
94
|
-
else
|
|
95
|
-
output.replace(compressed)
|
|
96
|
-
end
|
|
92
|
+
Omnizip::IO::Sink.for(output).write(compressed)
|
|
97
93
|
end
|
|
98
94
|
|
|
99
95
|
# Decompress LZMA2 data
|
|
100
96
|
def decompress(input, output, options = {})
|
|
101
97
|
# Read input data
|
|
102
|
-
input_data =
|
|
98
|
+
input_data = Omnizip::IO::Source.for(input).read
|
|
103
99
|
input_stream = StringIO.new(input_data)
|
|
104
100
|
input_stream.set_encoding(Encoding::BINARY)
|
|
105
101
|
|
|
@@ -120,11 +116,7 @@ module Omnizip
|
|
|
120
116
|
decompressed = decoder.decode_stream
|
|
121
117
|
|
|
122
118
|
# Write to output
|
|
123
|
-
|
|
124
|
-
output.write(decompressed)
|
|
125
|
-
else
|
|
126
|
-
output.replace(decompressed)
|
|
127
|
-
end
|
|
119
|
+
Omnizip::IO::Sink.for(output).write(decompressed)
|
|
128
120
|
end
|
|
129
121
|
|
|
130
122
|
# Encode dictionary size as single byte for LZMA2 properties
|
|
@@ -96,9 +96,7 @@ module Omnizip
|
|
|
96
96
|
# @param options [Models::CompressionOptions] Decompression options
|
|
97
97
|
# @return [void]
|
|
98
98
|
def decompress(input_stream, output_stream, _options = nil)
|
|
99
|
-
|
|
100
|
-
output_stream.set_encoding(Encoding::BINARY)
|
|
101
|
-
end
|
|
99
|
+
output_stream.set_encoding(Encoding::BINARY)
|
|
102
100
|
decoder = Decoder.new(input_stream)
|
|
103
101
|
decompressed = decoder.decode_stream
|
|
104
102
|
output_stream.write(decompressed)
|
data/lib/omnizip/algorithms.rb
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Omnizip
|
|
4
|
-
#
|
|
4
|
+
# High-level compression algorithm facades.
|
|
5
|
+
#
|
|
6
|
+
# Each top-level constant in this namespace (Deflate, BZip2, LZMA,
|
|
7
|
+
# LZMA2, Zstandard, PPMd7, PPMd8) is a facade that exposes the
|
|
8
|
+
# streaming +.compress+/+.decompress+ contract from +Omnizip::Algorithm+.
|
|
9
|
+
# Format-specific readers/writers call these facades for the actual
|
|
10
|
+
# compression work; the facades themselves do not know about archive
|
|
11
|
+
# container structure.
|
|
12
|
+
#
|
|
13
|
+
# Bit-level SDK ports (state machines, range coders, match finders)
|
|
14
|
+
# live under +Omnizip::Implementations+, not here. This namespace
|
|
15
|
+
# owns the *streaming contract*; that namespace owns the *primitives*.
|
|
16
|
+
# The boundary is: +Algorithms+ calls +Implementations+, never the
|
|
17
|
+
# reverse.
|
|
5
18
|
module Algorithms
|
|
6
19
|
autoload :PPMdBase, "omnizip/algorithms/ppmd_base"
|
|
7
20
|
autoload :LZMA2Const, "omnizip/algorithms/lzma2/constants"
|
|
@@ -185,29 +185,31 @@ module Omnizip
|
|
|
185
185
|
end
|
|
186
186
|
end
|
|
187
187
|
|
|
188
|
-
# Helper methods to handle different entry types
|
|
188
|
+
# Helper methods to handle different entry types. Each delegates
|
|
189
|
+
# to the Omnizip::Entry contract; format-specific accessors stay
|
|
190
|
+
# on the format entry classes themselves.
|
|
189
191
|
def entry_name(entry)
|
|
190
|
-
entry.
|
|
192
|
+
entry.entry_name || entry.to_s
|
|
191
193
|
end
|
|
192
194
|
|
|
193
195
|
def entry_directory?(entry)
|
|
194
|
-
entry.
|
|
196
|
+
entry.entry_directory?
|
|
195
197
|
end
|
|
196
198
|
|
|
197
199
|
def entry_size(entry)
|
|
198
|
-
entry.
|
|
200
|
+
entry.entry_size || 0
|
|
199
201
|
end
|
|
200
202
|
|
|
201
203
|
def entry_compressed_size(entry)
|
|
202
|
-
entry.
|
|
204
|
+
entry.compressed_size if entry.is_a?(Omnizip::Formats::SevenZip::Models::FileEntry)
|
|
203
205
|
end
|
|
204
206
|
|
|
205
207
|
def entry_has_stream?(entry)
|
|
206
|
-
entry.
|
|
208
|
+
entry.has_stream? if entry.is_a?(Omnizip::Formats::SevenZip::Models::FileEntry)
|
|
207
209
|
end
|
|
208
210
|
|
|
209
211
|
def entry_mtime(entry)
|
|
210
|
-
entry.
|
|
212
|
+
entry.entry_mtime
|
|
211
213
|
end
|
|
212
214
|
end
|
|
213
215
|
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Omnizip
|
|
4
|
+
# Mix-in that establishes the common contract every archive entry
|
|
5
|
+
# satisfies, regardless of format.
|
|
6
|
+
#
|
|
7
|
+
# Each format-specific entry class (Zip::Entry, Tar::Entry,
|
|
8
|
+
# SevenZip::Models::FileEntry, Iso::DirectoryRecord, Ole::Dirent,
|
|
9
|
+
# Xar::Entry, Rpm::Entry, Msi::Entry, Cpio::Entry, Rar3::Entry,
|
|
10
|
+
# Rar5::Entry, Xz::Entry, Metadata::EntryMetadata) includes this
|
|
11
|
+
# module so callers can rely on a single narrow interface instead
|
|
12
|
+
# of duck-typing through `respond_to?(:name) / :path / :filename`
|
|
13
|
+
# cascades.
|
|
14
|
+
#
|
|
15
|
+
# Including classes MUST override the four methods below. The
|
|
16
|
+
# defaults raise `NotImplementedError` to surface missing
|
|
17
|
+
# implementations at call time rather than at include time.
|
|
18
|
+
module Entry
|
|
19
|
+
# @return [String, nil] in-archive path, or nil if the entry has
|
|
20
|
+
# no name (e.g. empty anti-entry)
|
|
21
|
+
def entry_name
|
|
22
|
+
raise NotImplementedError,
|
|
23
|
+
"#{self.class} must implement #entry_name"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# @return [Boolean] true if the entry is a directory
|
|
27
|
+
def entry_directory?
|
|
28
|
+
raise NotImplementedError,
|
|
29
|
+
"#{self.class} must implement #entry_directory?"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# @return [Integer, nil] uncompressed size in bytes
|
|
33
|
+
def entry_size
|
|
34
|
+
raise NotImplementedError,
|
|
35
|
+
"#{self.class} must implement #entry_size"
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# @return [Time, nil] modification time
|
|
39
|
+
def entry_mtime
|
|
40
|
+
raise NotImplementedError,
|
|
41
|
+
"#{self.class} must implement #entry_mtime"
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -184,18 +184,10 @@ module Omnizip
|
|
|
184
184
|
|
|
185
185
|
# Get filename from entry
|
|
186
186
|
#
|
|
187
|
-
# @param entry [
|
|
187
|
+
# @param entry [#entry_name] Entry (Omnizip::Entry or compatible)
|
|
188
188
|
# @return [String] Filename
|
|
189
189
|
def entry_filename(entry)
|
|
190
|
-
|
|
191
|
-
entry.name
|
|
192
|
-
elsif entry.respond_to?(:path)
|
|
193
|
-
entry.path
|
|
194
|
-
elsif entry.respond_to?(:filename)
|
|
195
|
-
entry.filename
|
|
196
|
-
else
|
|
197
|
-
entry.to_s
|
|
198
|
-
end
|
|
190
|
+
entry.entry_name || entry.to_s
|
|
199
191
|
end
|
|
200
192
|
|
|
201
193
|
# Update progress tracker
|
|
@@ -36,7 +36,7 @@ module Omnizip
|
|
|
36
36
|
# Filters are applied in the order they are added during encoding,
|
|
37
37
|
# and in reverse order during decoding.
|
|
38
38
|
#
|
|
39
|
-
# @param filter [
|
|
39
|
+
# @param filter [Omnizip::Filter] Filter instance to add
|
|
40
40
|
# @return [self] For method chaining
|
|
41
41
|
def add_filter(filter)
|
|
42
42
|
@filters << filter
|
|
@@ -4,16 +4,18 @@ module Omnizip
|
|
|
4
4
|
class FilterRegistry < Omnizip::Registry
|
|
5
5
|
DEFAULT_FORMATS = %i[xz seven_zip].freeze
|
|
6
6
|
|
|
7
|
+
# Single source of truth for builtin filters. Each entry binds the
|
|
8
|
+
# filter name to its class and the formats that support it.
|
|
7
9
|
BUILTIN_FILTERS = {
|
|
8
|
-
"bcj-x86": "Omnizip::Filters::BcjX86",
|
|
9
|
-
"bcj-arm": "Omnizip::Filters::BcjArm",
|
|
10
|
-
"bcj-arm64": "Omnizip::Filters::BcjArm64",
|
|
11
|
-
"bcj-ia64": "Omnizip::Filters::BcjIa64",
|
|
12
|
-
"bcj-ppc": "Omnizip::Filters::BcjPpc",
|
|
13
|
-
"bcj-sparc": "Omnizip::Filters::BcjSparc",
|
|
14
|
-
bcj: "Omnizip::Filters::BCJ",
|
|
15
|
-
bcj2: "Omnizip::Filters::Bcj2",
|
|
16
|
-
delta: "Omnizip::Filters::Delta",
|
|
10
|
+
"bcj-x86": { const: "Omnizip::Filters::BcjX86", formats: %i[xz seven_zip] },
|
|
11
|
+
"bcj-arm": { const: "Omnizip::Filters::BcjArm", formats: %i[xz seven_zip] },
|
|
12
|
+
"bcj-arm64": { const: "Omnizip::Filters::BcjArm64", formats: [:seven_zip] },
|
|
13
|
+
"bcj-ia64": { const: "Omnizip::Filters::BcjIa64", formats: %i[xz seven_zip] },
|
|
14
|
+
"bcj-ppc": { const: "Omnizip::Filters::BcjPpc", formats: %i[xz seven_zip] },
|
|
15
|
+
"bcj-sparc": { const: "Omnizip::Filters::BcjSparc", formats: %i[xz seven_zip] },
|
|
16
|
+
bcj: { const: "Omnizip::Filters::BCJ", formats: [:seven_zip] },
|
|
17
|
+
bcj2: { const: "Omnizip::Filters::Bcj2", formats: [:seven_zip] },
|
|
18
|
+
delta: { const: "Omnizip::Filters::Delta", formats: %i[xz seven_zip] },
|
|
17
19
|
}.freeze
|
|
18
20
|
|
|
19
21
|
class << self
|
|
@@ -86,7 +88,6 @@ module Omnizip
|
|
|
86
88
|
|
|
87
89
|
trigger = lazy_triggers[normalized]
|
|
88
90
|
if trigger
|
|
89
|
-
synchronize { lazy_triggers.delete(normalized) }
|
|
90
91
|
trigger.call
|
|
91
92
|
entry = storage[normalized]
|
|
92
93
|
return entry if entry
|
|
@@ -98,12 +99,13 @@ module Omnizip
|
|
|
98
99
|
end
|
|
99
100
|
end
|
|
100
101
|
|
|
101
|
-
# Lazy triggers —
|
|
102
|
-
#
|
|
103
|
-
# overwrites the storage entry. Survives reset! because the
|
|
104
|
-
# proc is held by FilterRegistry, not the storage.
|
|
105
|
-
Omnizip::FilterRegistry::BUILTIN_FILTERS.
|
|
102
|
+
# Lazy triggers — each trigger resolves the filter's class (firing
|
|
103
|
+
# autoload) and registers it with its declared formats. Idempotent:
|
|
104
|
+
# register overwrites the storage entry. Survives reset! because the
|
|
105
|
+
# trigger proc is held by FilterRegistry, not the storage.
|
|
106
|
+
Omnizip::FilterRegistry::BUILTIN_FILTERS.each do |name, spec|
|
|
106
107
|
Omnizip::FilterRegistry.register_lazy(name) do
|
|
107
|
-
|
|
108
|
+
klass = Object.const_get(spec[:const])
|
|
109
|
+
Omnizip::FilterRegistry.register(name, klass, formats: spec[:formats])
|
|
108
110
|
end
|
|
109
111
|
end
|
data/lib/omnizip/filters/bcj2.rb
CHANGED
|
@@ -34,7 +34,7 @@ module Omnizip
|
|
|
34
34
|
# NOTE: Currently only decoding (decompression) is implemented.
|
|
35
35
|
# Encoding is extremely complex and will be added in a future version.
|
|
36
36
|
# For compression use cases, the simpler BCJ-x86 filter is recommended.
|
|
37
|
-
class Bcj2 <
|
|
37
|
+
class Bcj2 < Omnizip::Filter
|
|
38
38
|
# Encode is not currently supported for BCJ2.
|
|
39
39
|
#
|
|
40
40
|
# @param _data [String] Binary data to encode
|
|
@@ -28,7 +28,7 @@ module Omnizip
|
|
|
28
28
|
# The filter improves compression by making branch targets
|
|
29
29
|
# position-independent. The offset in ARM BL instructions is stored
|
|
30
30
|
# as word offset (divided by 4), and is relative to PC+8.
|
|
31
|
-
class BcjArm <
|
|
31
|
+
class BcjArm < Omnizip::Filter
|
|
32
32
|
# ARM BL (Branch and Link) opcode
|
|
33
33
|
OPCODE_BL = 0xEB
|
|
34
34
|
|
|
@@ -27,7 +27,7 @@ module Omnizip
|
|
|
27
27
|
#
|
|
28
28
|
# The filter improves compression by making branch targets and
|
|
29
29
|
# page-aligned addresses position-independent.
|
|
30
|
-
class BcjArm64 <
|
|
30
|
+
class BcjArm64 < Omnizip::Filter
|
|
31
31
|
# B/BL instruction base opcode
|
|
32
32
|
OPCODE_B_BL = 0x94000000
|
|
33
33
|
|
|
@@ -27,7 +27,7 @@ module Omnizip
|
|
|
27
27
|
#
|
|
28
28
|
# The filter improves compression by making branch targets
|
|
29
29
|
# position-independent.
|
|
30
|
-
class BcjIa64 <
|
|
30
|
+
class BcjIa64 < Omnizip::Filter
|
|
31
31
|
# Size of IA-64 instruction bundle (16 bytes, little-endian)
|
|
32
32
|
BUNDLE_SIZE = 16
|
|
33
33
|
|
data/lib/omnizip/filters.rb
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
module Omnizip
|
|
4
4
|
# Filter implementations for preprocessing data before compression
|
|
5
5
|
module Filters
|
|
6
|
-
autoload :FilterBase, "omnizip/filters/filter_base"
|
|
7
6
|
autoload :BCJ, "omnizip/filters/bcj"
|
|
8
7
|
autoload :BcjX86, "omnizip/filters/bcj_x86"
|
|
9
8
|
autoload :Bcj2, "omnizip/filters/bcj2"
|
|
@@ -17,6 +16,5 @@ module Omnizip
|
|
|
17
16
|
autoload :BcjSparc, "omnizip/filters/bcj_sparc"
|
|
18
17
|
autoload :BcjIa64, "omnizip/filters/bcj_ia64"
|
|
19
18
|
autoload :Delta, "omnizip/filters/delta"
|
|
20
|
-
autoload :Registry, "omnizip/filters/registry"
|
|
21
19
|
end
|
|
22
20
|
end
|
|
@@ -112,12 +112,6 @@ module Omnizip
|
|
|
112
112
|
output_io.write(decompressed_io.read)
|
|
113
113
|
end
|
|
114
114
|
|
|
115
|
-
# Register BZIP2 format when loaded
|
|
116
|
-
def register!
|
|
117
|
-
FormatRegistry.register(".bz2", Omnizip::Formats::Bzip2File)
|
|
118
|
-
FormatRegistry.register(".bzip2", Omnizip::Formats::Bzip2File)
|
|
119
|
-
end
|
|
120
|
-
|
|
121
115
|
private
|
|
122
116
|
|
|
123
117
|
# Write BZIP2 header
|
|
@@ -163,4 +157,3 @@ module Omnizip
|
|
|
163
157
|
end
|
|
164
158
|
end
|
|
165
159
|
end
|
|
166
|
-
|
|
@@ -8,6 +8,7 @@ module Omnizip
|
|
|
8
8
|
# Represents a file, directory, or special file in a CPIO archive.
|
|
9
9
|
# Supports newc, CRC, and ODC formats.
|
|
10
10
|
class Entry
|
|
11
|
+
include Omnizip::Entry
|
|
11
12
|
include Omnizip::Formats::Cpio::Constants
|
|
12
13
|
|
|
13
14
|
# @return [String] Magic number identifying format
|
|
@@ -58,6 +59,11 @@ module Omnizip
|
|
|
58
59
|
# @return [String] File data
|
|
59
60
|
attr_accessor :data
|
|
60
61
|
|
|
62
|
+
def entry_name = name
|
|
63
|
+
def entry_directory? = directory?
|
|
64
|
+
def entry_size = filesize
|
|
65
|
+
def entry_mtime = mtime
|
|
66
|
+
|
|
61
67
|
# Initialize CPIO entry
|
|
62
68
|
#
|
|
63
69
|
# @param attributes [Hash] Entry attributes
|
data/lib/omnizip/formats/cpio.rb
CHANGED
data/lib/omnizip/formats/gzip.rb
CHANGED
|
@@ -127,12 +127,6 @@ module Omnizip
|
|
|
127
127
|
metadata
|
|
128
128
|
end
|
|
129
129
|
|
|
130
|
-
# Register GZIP format when loaded
|
|
131
|
-
def register!
|
|
132
|
-
FormatRegistry.register(".gz", Omnizip::Formats::Gzip)
|
|
133
|
-
FormatRegistry.register(".gzip", Omnizip::Formats::Gzip)
|
|
134
|
-
end
|
|
135
|
-
|
|
136
130
|
private
|
|
137
131
|
|
|
138
132
|
# Write GZIP header
|
|
@@ -231,4 +225,3 @@ module Omnizip
|
|
|
231
225
|
end
|
|
232
226
|
end
|
|
233
227
|
end
|
|
234
|
-
|
|
@@ -6,9 +6,16 @@ module Omnizip
|
|
|
6
6
|
# ISO 9660 Directory Record
|
|
7
7
|
# Represents a file or directory entry
|
|
8
8
|
class DirectoryRecord
|
|
9
|
+
include Omnizip::Entry
|
|
10
|
+
|
|
9
11
|
attr_accessor :full_path
|
|
10
12
|
attr_reader :length, :extended_attr_length, :location, :data_length, :recording_date, :flags, :file_unit_size, :interleave_gap_size, :volume_sequence_number, :name, :system_use
|
|
11
13
|
|
|
14
|
+
def entry_name = full_path || name
|
|
15
|
+
def entry_directory? = directory?
|
|
16
|
+
def entry_size = data_length
|
|
17
|
+
def entry_mtime = recording_date
|
|
18
|
+
|
|
12
19
|
# Set the full path for this record, used by Reader when walking
|
|
13
20
|
# a directory tree. Allows callers to look up records by path
|
|
14
21
|
# without re-joining parent names.
|
data/lib/omnizip/formats/iso.rb
CHANGED
data/lib/omnizip/formats/lzip.rb
CHANGED
|
@@ -132,12 +132,6 @@ module Omnizip
|
|
|
132
132
|
}
|
|
133
133
|
end
|
|
134
134
|
|
|
135
|
-
# Register LZIP format when loaded
|
|
136
|
-
def register!
|
|
137
|
-
FormatRegistry.register(".lz", Omnizip::Formats::Lzip)
|
|
138
|
-
FormatRegistry.register(".lzip", Omnizip::Formats::Lzip)
|
|
139
|
-
end
|
|
140
|
-
|
|
141
135
|
# Detect if data is LZIP format
|
|
142
136
|
#
|
|
143
137
|
# @param data [String] Data to check
|
|
@@ -149,4 +143,3 @@ module Omnizip
|
|
|
149
143
|
end
|
|
150
144
|
end
|
|
151
145
|
end
|
|
152
|
-
|
|
@@ -138,13 +138,7 @@ module Omnizip
|
|
|
138
138
|
uncompressed_size: decoder.uncompressed_size,
|
|
139
139
|
}
|
|
140
140
|
end
|
|
141
|
-
|
|
142
|
-
# Register LZMA_Alone format when loaded
|
|
143
|
-
def register!
|
|
144
|
-
FormatRegistry.register(".lzma", Omnizip::Formats::LzmaAlone)
|
|
145
|
-
end
|
|
146
141
|
end
|
|
147
142
|
end
|
|
148
143
|
end
|
|
149
144
|
end
|
|
150
|
-
|
|
@@ -8,8 +8,14 @@ module Omnizip
|
|
|
8
8
|
# Represents a single file within an MSI package.
|
|
9
9
|
# File information is assembled from File, Component, and Directory tables.
|
|
10
10
|
class Entry
|
|
11
|
+
include Omnizip::Entry
|
|
11
12
|
include Omnizip::Formats::Msi::Constants
|
|
12
13
|
|
|
14
|
+
def entry_name = path
|
|
15
|
+
def entry_directory? = false
|
|
16
|
+
def entry_size = size
|
|
17
|
+
def entry_mtime = nil
|
|
18
|
+
|
|
13
19
|
# @return [String] Full installation path
|
|
14
20
|
attr_accessor :path
|
|
15
21
|
|
data/lib/omnizip/formats/msi.rb
CHANGED
|
@@ -67,16 +67,7 @@ module Omnizip
|
|
|
67
67
|
def info(path)
|
|
68
68
|
open(path, &:info)
|
|
69
69
|
end
|
|
70
|
-
|
|
71
|
-
# Register MSI format with format registry
|
|
72
|
-
#
|
|
73
|
-
# This overrides OLE's .msi registration.
|
|
74
|
-
def register!
|
|
75
|
-
FormatRegistry.register(".msi", self)
|
|
76
|
-
FormatRegistry.register(".msp", self)
|
|
77
|
-
end
|
|
78
70
|
end
|
|
79
71
|
end
|
|
80
72
|
end
|
|
81
73
|
end
|
|
82
|
-
|
|
@@ -8,8 +8,14 @@ module Omnizip
|
|
|
8
8
|
# Represents a file or directory entry in an OLE compound document.
|
|
9
9
|
# Each dirent is 128 bytes and contains metadata about the entry.
|
|
10
10
|
class Dirent
|
|
11
|
+
include Omnizip::Entry
|
|
11
12
|
include Omnizip::Formats::Ole::Constants
|
|
12
13
|
|
|
14
|
+
def entry_name = name
|
|
15
|
+
def entry_directory? = dir?
|
|
16
|
+
def entry_size = nil
|
|
17
|
+
def entry_mtime = modify_time
|
|
18
|
+
|
|
13
19
|
# Pack format for dirent structure
|
|
14
20
|
PACK = "a64 v C C V3 a16 V a8 a8 V2 a4"
|
|
15
21
|
|
data/lib/omnizip/formats/ole.rb
CHANGED
|
@@ -117,14 +117,6 @@ module Omnizip
|
|
|
117
117
|
end
|
|
118
118
|
end
|
|
119
119
|
|
|
120
|
-
# Register OLE format in registry
|
|
121
|
-
def register!
|
|
122
|
-
FormatRegistry.register(".ole", Storage)
|
|
123
|
-
FormatRegistry.register(".doc", Storage)
|
|
124
|
-
FormatRegistry.register(".xls", Storage)
|
|
125
|
-
FormatRegistry.register(".ppt", Storage)
|
|
126
|
-
end
|
|
127
|
-
|
|
128
120
|
private
|
|
129
121
|
|
|
130
122
|
# Recursively extract dirent to directory
|
|
@@ -147,4 +139,3 @@ module Omnizip
|
|
|
147
139
|
end
|
|
148
140
|
end
|
|
149
141
|
end
|
|
150
|
-
|