omnizip 0.3.51 → 0.3.53

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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +56 -0
  3. data/lib/omnizip/archive_handlers/seven_zip_handler.rb +1 -1
  4. data/lib/omnizip/archive_handlers/zip_handler.rb +1 -1
  5. data/lib/omnizip/buffer/memory_extractor.rb +3 -16
  6. data/lib/omnizip/buffer/seven_zip_bridge.rb +13 -0
  7. data/lib/omnizip/buffer.rb +23 -21
  8. data/lib/omnizip/checksums/verifier.rb +2 -2
  9. data/lib/omnizip/chunked.rb +14 -21
  10. data/lib/omnizip/cli/output_formatter.rb +16 -8
  11. data/lib/omnizip/cli.rb +1 -7
  12. data/lib/omnizip/commands/archive_create_command.rb +1 -10
  13. data/lib/omnizip/commands/archive_extract_command.rb +4 -13
  14. data/lib/omnizip/commands/archive_list_command.rb +1 -18
  15. data/lib/omnizip/commands/metadata_command.rb +21 -26
  16. data/lib/omnizip/commands/parity_create_command.rb +1 -7
  17. data/lib/omnizip/extraction/selective_extractor.rb +16 -4
  18. data/lib/omnizip/formats/cpio/reader.rb +1 -1
  19. data/lib/omnizip/formats/iso/reader.rb +3 -3
  20. data/lib/omnizip/formats/iso/volume_descriptor.rb +2 -2
  21. data/lib/omnizip/formats/rar/compression/ppmd/decoder.rb +0 -20
  22. data/lib/omnizip/formats/rar/decompressor.rb +7 -7
  23. data/lib/omnizip/formats/rar/reader.rb +2 -2
  24. data/lib/omnizip/formats/rpm.rb +4 -4
  25. data/lib/omnizip/formats/seven_zip/reader.rb +1 -1
  26. data/lib/omnizip/formats/seven_zip/split_archive_reader.rb +1 -1
  27. data/lib/omnizip/formats/xar/reader.rb +2 -2
  28. data/lib/omnizip/formats/zip/reader.rb +96 -8
  29. data/lib/omnizip/models/conversion_result.rb +76 -70
  30. data/lib/omnizip/models/filter_config.rb +34 -44
  31. data/lib/omnizip/models/match_result.rb +35 -18
  32. data/lib/omnizip/models/optimization_suggestion.rb +45 -41
  33. data/lib/omnizip/models/performance_result.rb +53 -47
  34. data/lib/omnizip/models/profile_report.rb +70 -36
  35. data/lib/omnizip/parallel/parallel_extractor.rb +2 -2
  36. data/lib/omnizip/parallel/worker_pool.rb +3 -3
  37. data/lib/omnizip/parity/par2_creator.rb +0 -34
  38. data/lib/omnizip/parity/par2_verifier.rb +5 -0
  39. data/lib/omnizip/profiler/report_generator.rb +2 -13
  40. data/lib/omnizip/profiler.rb +1 -12
  41. data/lib/omnizip/temp/safe_extract.rb +3 -43
  42. data/lib/omnizip/version.rb +1 -1
  43. data/lib/omnizip/zip/file.rb +1 -1
  44. metadata +1 -1
@@ -1,24 +1,46 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "lutaml/model"
4
+
3
5
  module Omnizip
4
6
  module Models
5
- # Represents the result of pattern matching against archive entries
7
+ # Represents the result of pattern matching against archive entries.
6
8
  #
7
- # Contains matched entries with metadata about the matching process.
8
- class MatchResult
9
+ # Serialized via lutaml-model — no hand-rolled +to_h+ / +to_json+.
10
+ # The serialized "matches" is the match COUNT (not the entry
11
+ # objects, which are arbitrary caller types); the live entry
12
+ # collection stays a plain reader.
13
+ class MatchResult < Lutaml::Model::Serializable
9
14
  include Enumerable
10
15
 
11
- attr_reader :matches, :total_scanned, :pattern
16
+ attribute :total_scanned, :integer, default: 0
17
+
18
+ attribute :pattern_repr, :string, method: :pattern_to_s
19
+ attribute :match_count, :integer, method: :count
20
+ attribute :rate, :double, method: :match_rate
21
+
22
+ key_value do
23
+ map "pattern", to: :pattern_repr,
24
+ render_default: true, render_nil: true
25
+ map "matches", to: :match_count,
26
+ render_default: true, render_nil: true
27
+ map "scanned", to: :total_scanned,
28
+ render_default: true, render_nil: true
29
+ map "match_rate", to: :rate,
30
+ render_default: true, render_nil: true
31
+ end
32
+
33
+ attr_reader :matches, :pattern
12
34
 
13
35
  # Initialize a new match result
14
36
  #
15
37
  # @param pattern [Object] The pattern that was matched
16
38
  # @param matches [Array] Array of matched entries
17
39
  # @param total_scanned [Integer] Total entries scanned
18
- def initialize(pattern, matches: [], total_scanned: 0)
40
+ def initialize(pattern = nil, matches: [], total_scanned: 0)
41
+ super(total_scanned: total_scanned)
19
42
  @pattern = pattern
20
43
  @matches = Array(matches)
21
- @total_scanned = total_scanned
22
44
  end
23
45
 
24
46
  # Add a matched entry
@@ -35,7 +57,7 @@ module Omnizip
35
57
  # @param count [Integer] Number to increment by
36
58
  # @return [self]
37
59
  def increment_scanned(count = 1)
38
- @total_scanned += count
60
+ self.total_scanned = total_scanned + count
39
61
  self
40
62
  end
41
63
 
@@ -64,9 +86,9 @@ module Omnizip
64
86
  #
65
87
  # @return [Float] Match rate between 0.0 and 1.0
66
88
  def match_rate
67
- return 0.0 if @total_scanned.zero?
89
+ return 0.0 if total_scanned.zero?
68
90
 
69
- count.to_f / @total_scanned
91
+ count.to_f / total_scanned
70
92
  end
71
93
 
72
94
  # Get match percentage
@@ -108,16 +130,11 @@ module Omnizip
108
130
  @matches.dup
109
131
  end
110
132
 
111
- # Get summary hash
133
+ # Serialized pattern representation.
112
134
  #
113
- # @return [Hash]
114
- def to_h
115
- {
116
- pattern: @pattern.to_s,
117
- matches: count,
118
- scanned: @total_scanned,
119
- match_rate: match_rate,
120
- }
135
+ # @return [String] The pattern as a string
136
+ def pattern_to_s
137
+ @pattern.to_s
121
138
  end
122
139
  end
123
140
  end
@@ -1,41 +1,60 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "lutaml/model"
4
+
3
5
  module Omnizip
4
6
  module Models
5
- # Represents a performance optimization suggestion based on profiling data
6
- class OptimizationSuggestion
7
+ # Represents a performance optimization suggestion based on
8
+ # profiling data.
9
+ #
10
+ # Serialized via lutaml-model — no hand-rolled +to_h+ / +to_json+.
11
+ # The priority_score key serializes the derived #priority_score
12
+ # method under a distinct attribute name.
13
+ class OptimizationSuggestion < Lutaml::Model::Serializable
7
14
  SEVERITY_LEVELS = %i[low medium high critical].freeze
8
15
  CATEGORIES = %i[
9
16
  memory cpu hotpath algorithm io gc allocation concurrency
10
17
  ].freeze
11
18
 
12
- attr_reader :title, :description, :severity, :category, :impact_estimate,
13
- :implementation_effort, :related_operations, :code_locations,
14
- :metrics
19
+ attribute :title, :string
20
+ attribute :description, :string
21
+ attribute :severity, :symbol
22
+ attribute :category, :symbol
23
+ attribute :impact_estimate, :double
24
+ attribute :implementation_effort, :double
25
+ attribute :related_operations, :string, collection: true, default: []
26
+ attribute :code_locations, :string, collection: true, default: []
27
+ attribute :metrics, :hash, default: {}
28
+
29
+ attribute :priority, :double, method: :priority_score
30
+
31
+ key_value do
32
+ map "title", to: :title, render_default: true, render_nil: true
33
+ map "description", to: :description,
34
+ render_default: true, render_nil: true
35
+ map "severity", to: :severity, render_default: true, render_nil: true
36
+ map "category", to: :category, render_default: true, render_nil: true
37
+ map "impact_estimate", to: :impact_estimate,
38
+ render_default: true, render_nil: true
39
+ map "implementation_effort", to: :implementation_effort,
40
+ render_default: true, render_nil: true
41
+ map "priority_score", to: :priority,
42
+ render_default: true, render_nil: true
43
+ map "related_operations", to: :related_operations,
44
+ render_default: true, render_nil: true
45
+ map "code_locations", to: :code_locations,
46
+ render_default: true, render_nil: true
47
+ map "metrics", to: :metrics, render_default: true, render_nil: true
48
+ end
15
49
 
16
- def initialize(
17
- title:,
18
- description:,
19
- severity:,
20
- category:,
21
- impact_estimate: nil,
22
- implementation_effort: nil,
23
- related_operations: [],
24
- code_locations: [],
25
- metrics: {}
26
- )
50
+ # Severity and category are validated after the framework
51
+ # constructor assigns the attributes. Empty-collection defaults
52
+ # are assigned explicitly (lutaml-model 0.8.x drops them).
53
+ def initialize(attrs = {})
54
+ super({ related_operations: [], code_locations: [],
55
+ metrics: {} }.merge(attrs))
27
56
  validate_severity!(severity)
28
57
  validate_category!(category)
29
-
30
- @title = title
31
- @description = description
32
- @severity = severity
33
- @category = category
34
- @impact_estimate = impact_estimate
35
- @implementation_effort = implementation_effort
36
- @related_operations = related_operations
37
- @code_locations = code_locations
38
- @metrics = metrics
39
58
  end
40
59
 
41
60
  def critical?
@@ -54,21 +73,6 @@ module Omnizip
54
73
  severity_weight * impact_weight * effort_weight
55
74
  end
56
75
 
57
- def to_h
58
- {
59
- title: title,
60
- description: description,
61
- severity: severity,
62
- category: category,
63
- impact_estimate: impact_estimate,
64
- implementation_effort: implementation_effort,
65
- priority_score: priority_score,
66
- related_operations: related_operations,
67
- code_locations: code_locations,
68
- metrics: metrics,
69
- }
70
- end
71
-
72
76
  private
73
77
 
74
78
  def validate_severity!(severity)
@@ -1,35 +1,60 @@
1
- # frozen_string_literal: true
1
+ # frozen_string: true
2
+
3
+ require "lutaml/model"
2
4
 
3
5
  module Omnizip
4
6
  module Models
5
- # Represents the performance characteristics of a profiled operation
6
- class PerformanceResult
7
- attr_reader :operation_name, :total_time, :cpu_time, :wall_time,
8
- :memory_allocated, :memory_retained, :object_allocations,
9
- :gc_runs, :call_count, :timestamp
7
+ # Represents the performance characteristics of a profiled operation.
8
+ #
9
+ # Serialized via lutaml-model — no hand-rolled +to_h+ / +to_json+.
10
+ # The derived-rate keys serialize the calculation methods; attribute
11
+ # names differ from the keys so generated readers do not shadow them.
12
+ class PerformanceResult < Lutaml::Model::Serializable
13
+ attribute :operation_name, :string
14
+ attribute :total_time, :double
15
+ attribute :cpu_time, :double
16
+ attribute :wall_time, :double
17
+ attribute :memory_allocated, :integer
18
+ attribute :memory_retained, :integer
19
+ attribute :object_allocations, :integer
20
+ attribute :gc_runs, :integer
21
+ attribute :call_count, :integer
22
+ attribute :timestamp, :date_time, default: -> { Time.now }
23
+
24
+ attribute :throughput, :double, method: :throughput_ops_per_second
25
+ attribute :average_time, :double, method: :average_time_per_operation
26
+ attribute :memory_per_op, :double, method: :memory_per_operation
27
+ attribute :pressure, :double, method: :gc_pressure
10
28
 
11
- def initialize(
12
- operation_name:,
13
- total_time: nil,
14
- cpu_time: nil,
15
- wall_time: nil,
16
- memory_allocated: nil,
17
- memory_retained: nil,
18
- object_allocations: nil,
19
- gc_runs: nil,
20
- call_count: nil,
21
- timestamp: Time.now
22
- )
23
- @operation_name = operation_name
24
- @total_time = total_time
25
- @cpu_time = cpu_time
26
- @wall_time = wall_time
27
- @memory_allocated = memory_allocated
28
- @memory_retained = memory_retained
29
- @object_allocations = object_allocations
30
- @gc_runs = gc_runs
31
- @call_count = call_count
32
- @timestamp = timestamp
29
+ key_value do
30
+ map "operation_name", to: :operation_name,
31
+ render_default: true, render_nil: true
32
+ map "total_time", to: :total_time,
33
+ render_default: true, render_nil: true
34
+ map "cpu_time", to: :cpu_time,
35
+ render_default: true, render_nil: true
36
+ map "wall_time", to: :wall_time,
37
+ render_default: true, render_nil: true
38
+ map "memory_allocated", to: :memory_allocated,
39
+ render_default: true, render_nil: true
40
+ map "memory_retained", to: :memory_retained,
41
+ render_default: true, render_nil: true
42
+ map "object_allocations", to: :object_allocations,
43
+ render_default: true, render_nil: true
44
+ map "gc_runs", to: :gc_runs,
45
+ render_default: true, render_nil: true
46
+ map "call_count", to: :call_count,
47
+ render_default: true, render_nil: true
48
+ map "throughput_ops_per_second", to: :throughput,
49
+ render_default: true, render_nil: true
50
+ map "average_time_per_operation", to: :average_time,
51
+ render_default: true, render_nil: true
52
+ map "memory_per_operation", to: :memory_per_op,
53
+ render_default: true, render_nil: true
54
+ map "gc_pressure", to: :pressure,
55
+ render_default: true, render_nil: true
56
+ map "timestamp", to: :timestamp,
57
+ render_default: true, render_nil: true
33
58
  end
34
59
 
35
60
  def throughput_ops_per_second
@@ -55,25 +80,6 @@ module Omnizip
55
80
 
56
81
  gc_runs.to_f / total_time
57
82
  end
58
-
59
- def to_h
60
- {
61
- operation_name: operation_name,
62
- total_time: total_time,
63
- cpu_time: cpu_time,
64
- wall_time: wall_time,
65
- memory_allocated: memory_allocated,
66
- memory_retained: memory_retained,
67
- object_allocations: object_allocations,
68
- gc_runs: gc_runs,
69
- call_count: call_count,
70
- throughput_ops_per_second: throughput_ops_per_second,
71
- average_time_per_operation: average_time_per_operation,
72
- memory_per_operation: memory_per_operation,
73
- gc_pressure: gc_pressure,
74
- timestamp: timestamp.iso8601,
75
- }
76
- end
77
83
  end
78
84
  end
79
85
  end
@@ -1,26 +1,65 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "lutaml/model"
4
+
3
5
  module Omnizip
4
6
  module Models
5
- # Represents an aggregated profiling report with hot path analysis
6
- class ProfileReport
7
- attr_reader :profile_name, :results, :hot_paths, :bottlenecks,
8
- :timestamp, :metadata
7
+ # Aggregated profiling report with hot path analysis.
8
+ #
9
+ # Serialized via lutaml-model — no hand-rolled +to_h+ / +to_json+.
10
+ # The +summary+ key serializes a nested Summary model built from
11
+ # the report's aggregates; hot paths and bottlenecks are the
12
+ # analyzer-supplied hashes.
13
+ class ProfileReport < Lutaml::Model::Serializable
14
+ # Aggregate block of {ProfileReport#to_hash}.
15
+ class Summary < Lutaml::Model::Serializable
16
+ attribute :total_execution_time, :double, default: 0.0
17
+ attribute :total_memory_allocated, :integer, default: 0
18
+ attribute :total_gc_runs, :integer, default: 0
19
+ attribute :operation_count, :integer, default: 0
20
+
21
+ key_value do
22
+ map "total_execution_time", to: :total_execution_time,
23
+ render_default: true, render_nil: true
24
+ map "total_memory_allocated", to: :total_memory_allocated,
25
+ render_default: true, render_nil: true
26
+ map "total_gc_runs", to: :total_gc_runs,
27
+ render_default: true, render_nil: true
28
+ map "operation_count", to: :operation_count,
29
+ render_default: true, render_nil: true
30
+ end
31
+ end
32
+
33
+ attribute :profile_name, :string
34
+ attribute :results, PerformanceResult, collection: true, default: []
35
+ attribute :hot_paths, :hash, collection: true, default: []
36
+ attribute :bottlenecks, :hash, collection: true, default: []
37
+ attribute :timestamp, :date_time, default: -> { Time.now }
38
+ attribute :metadata, :hash, default: {}
39
+ attribute :summary, Summary, method: :build_summary
40
+
41
+ key_value do
42
+ map "profile_name", to: :profile_name,
43
+ render_default: true, render_nil: true
44
+ map "timestamp", to: :timestamp,
45
+ render_default: true, render_nil: true
46
+ map "summary", to: :summary,
47
+ render_default: true, render_nil: true
48
+ map "results", to: :results,
49
+ render_default: true, render_nil: true
50
+ map "hot_paths", to: :hot_paths,
51
+ render_default: true, render_nil: true
52
+ map "bottlenecks", to: :bottlenecks,
53
+ render_default: true, render_nil: true
54
+ map "metadata", to: :metadata,
55
+ render_default: true, render_nil: true
56
+ end
9
57
 
10
- def initialize(
11
- profile_name:,
12
- results: [],
13
- hot_paths: [],
14
- bottlenecks: [],
15
- timestamp: Time.now,
16
- metadata: {}
17
- )
18
- @profile_name = profile_name
19
- @results = results
20
- @hot_paths = hot_paths
21
- @bottlenecks = bottlenecks
22
- @timestamp = timestamp
23
- @metadata = metadata
58
+ # lutaml-model 0.8.x does not render empty-collection defaults,
59
+ # so they are assigned explicitly to keep every key present.
60
+ def initialize(attrs = {})
61
+ super({ results: [], hot_paths: [], bottlenecks: [],
62
+ metadata: {} }.merge(attrs))
24
63
  end
25
64
 
26
65
  def total_execution_time
@@ -50,32 +89,27 @@ module Omnizip
50
89
  end
51
90
 
52
91
  def add_result(result)
53
- @results << result
92
+ results << result
54
93
  end
55
94
 
56
95
  def add_hot_path(hot_path)
57
- @hot_paths << hot_path
96
+ hot_paths << hot_path
58
97
  end
59
98
 
60
99
  def add_bottleneck(bottleneck)
61
- @bottlenecks << bottleneck
100
+ bottlenecks << bottleneck
62
101
  end
63
102
 
64
- def to_h
65
- {
66
- profile_name: profile_name,
67
- timestamp: timestamp.iso8601,
68
- summary: {
69
- total_execution_time: total_execution_time,
70
- total_memory_allocated: total_memory_allocated,
71
- total_gc_runs: total_gc_runs,
72
- operation_count: results.size,
73
- },
74
- results: results.map(&:to_h),
75
- hot_paths: hot_paths,
76
- bottlenecks: bottlenecks,
77
- metadata: metadata,
78
- }
103
+ # Serialized aggregate block.
104
+ #
105
+ # @return [Summary]
106
+ def build_summary
107
+ Summary.new(
108
+ total_execution_time: total_execution_time,
109
+ total_memory_allocated: total_memory_allocated,
110
+ total_gc_runs: total_gc_runs,
111
+ operation_count: results.size,
112
+ )
79
113
  end
80
114
  end
81
115
  end
@@ -87,7 +87,7 @@ module Omnizip
87
87
  ::File.open(archive_path, "rb") do |io|
88
88
  # Find the entry in reader
89
89
  reader_entry = reader.entries.find { |e| e.filename == entry.name }
90
- raise "Entry not found in archive: #{entry.name}" unless reader_entry
90
+ raise Errno::ENOENT, "Entry not found in archive: #{entry.name}" unless reader_entry
91
91
 
92
92
  # Seek to entry data
93
93
  io.seek(reader_entry.local_header_offset, ::IO::SEEK_SET)
@@ -288,7 +288,7 @@ module Omnizip
288
288
  @write_mutex.synchronize do
289
289
  # Check if file exists
290
290
  if ::File.exist?(dest_path) && !overwrite
291
- raise "File exists: #{dest_path}"
291
+ raise Errno::EEXIST, "File exists: #{dest_path}"
292
292
  end
293
293
 
294
294
  # Write file or create directory
@@ -93,7 +93,7 @@ module Omnizip
93
93
  # @param work [Fractor::Work] work item to process
94
94
  # @return [void]
95
95
  def submit(work)
96
- raise "Worker pool not started" unless @running
96
+ raise Omnizip::IOError, "Worker pool not started" unless @running
97
97
 
98
98
  if @continuous
99
99
  # In continuous mode, add to work queue
@@ -116,8 +116,8 @@ module Omnizip
116
116
  #
117
117
  # @return [void]
118
118
  def run
119
- raise "Can only run in batch mode" if @continuous
120
- raise "Worker pool not started" unless @running
119
+ raise Omnizip::IOError, "Can only run in batch mode" if @continuous
120
+ raise Omnizip::IOError, "Worker pool not started" unless @running
121
121
 
122
122
  @supervisor.run
123
123
 
@@ -161,40 +161,6 @@ progress: nil)
161
161
  Digest::MD5.digest("#{Time.now.to_f}#{rand}")
162
162
  end
163
163
 
164
- # Analyze file and calculate hashes
165
- #
166
- # @param file_path [String] Path to file
167
- # @return [FileInfo] File information
168
- def analyze_file(file_path)
169
- File.open(file_path, "rb") do |io|
170
- file_size = io.size
171
-
172
- # Calculate hash of first 16KB
173
- first_16k = io.read(16384) || ""
174
- hash_16k = Digest::MD5.digest(first_16k)
175
-
176
- # Calculate full file hash
177
- io.rewind
178
- hash_full = Digest::MD5.file(file_path).digest
179
-
180
- # Generate file ID
181
- file_id = Digest::MD5.digest("#{File.basename(file_path)}#{file_size}")
182
-
183
- # Read file blocks
184
- io.rewind
185
- blocks = read_file_blocks(io)
186
-
187
- FileInfo.new(
188
- path: file_path,
189
- file_id: file_id,
190
- hash_16k: hash_16k,
191
- hash_full: hash_full,
192
- size: file_size,
193
- blocks: blocks,
194
- )
195
- end
196
- end
197
-
198
164
  # Read file data into blocks
199
165
  #
200
166
  # @param io [IO] File IO object
@@ -69,6 +69,11 @@ module Omnizip
69
69
  # @param par2_file [String] Path to .par2 index file
70
70
  # @raise [ArgumentError] if file doesn't exist
71
71
  def initialize(par2_file)
72
+ if par2_file.nil?
73
+ raise ArgumentError,
74
+ "PAR2 file is nil — no index .par2 was produced for this set"
75
+ end
76
+
72
77
  raise ArgumentError, "PAR2 file not found: #{par2_file}" unless
73
78
  File.exist?(par2_file)
74
79
 
@@ -33,7 +33,7 @@ module Omnizip
33
33
 
34
34
  # Generate a JSON report
35
35
  def generate_json_report
36
- JSON.pretty_generate(report.to_h)
36
+ JSON.pretty_generate(report.to_hash)
37
37
  end
38
38
 
39
39
  # Save report to file
@@ -145,18 +145,7 @@ module Omnizip
145
145
  end
146
146
 
147
147
  def format_bytes(bytes)
148
- return "0 B" if bytes.nil? || bytes.zero?
149
-
150
- units = %w[B KB MB GB]
151
- size = bytes.to_f
152
- unit_index = 0
153
-
154
- while size >= 1024.0 && unit_index < units.size - 1
155
- size /= 1024.0
156
- unit_index += 1
157
- end
158
-
159
- format("%.2f %s", size, units[unit_index])
148
+ Omnizip::CliOutputFormatter.format_size(bytes)
160
149
  end
161
150
 
162
151
  def truncate(string, max_length)
@@ -186,18 +186,7 @@ module Omnizip
186
186
  end
187
187
 
188
188
  def format_bytes(bytes)
189
- return "0 B" if bytes.zero?
190
-
191
- units = %w[B KB MB GB]
192
- size = bytes.to_f
193
- unit_index = 0
194
-
195
- while size >= 1024.0 && unit_index < units.size - 1
196
- size /= 1024.0
197
- unit_index += 1
198
- end
199
-
200
- format("%.2f %s", size, units[unit_index])
189
+ Omnizip::CliOutputFormatter.format_size(bytes)
201
190
  end
202
191
  end
203
192
  end
@@ -79,37 +79,9 @@ module Omnizip
79
79
  private
80
80
 
81
81
  def extract_to_temp(temp_dir)
82
- # Detect archive format and extract
83
- case detect_format
84
- when :zip
85
- extract_zip(temp_dir)
86
- when :seven_zip
87
- extract_7z(temp_dir)
88
- else
89
- raise Omnizip::UnsupportedFormatError,
90
- "Unknown archive format: #{@archive_path}"
91
- end
92
- end
93
-
94
- def extract_zip(dest)
95
- Omnizip::Zip::File.open(@archive_path) do |zip|
96
- zip.each do |entry|
97
- entry_path = File.join(dest, entry.name)
98
-
99
- if entry.directory?
100
- FileUtils.mkdir_p(entry_path)
101
- else
102
- FileUtils.mkdir_p(File.dirname(entry_path))
103
- zip.extract(entry, entry_path)
104
- end
105
- end
106
- end
107
- end
108
-
109
- def extract_7z(dest)
110
- # Placeholder for 7z extraction
111
- # Would use Omnizip::SevenZip::File when available
112
- raise NotImplementedError, "7z extraction not yet implemented"
82
+ # Every routed format extracts through the handler registry,
83
+ # same as the convenience API
84
+ Omnizip.extract_archive(@archive_path, temp_dir)
113
85
  end
114
86
 
115
87
  def move_to_destination(temp_dir)
@@ -147,18 +119,6 @@ module Omnizip
147
119
  end
148
120
  count
149
121
  end
150
-
151
- def detect_format
152
- File.open(@archive_path, "rb") do |f|
153
- magic = f.read(4)
154
- case magic
155
- when "PK\x03\x04"
156
- :zip
157
- when "7z\xBC\xAF"
158
- :seven_zip
159
- end
160
- end
161
- end
162
122
  end
163
123
  end
164
124
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Omnizip
4
- VERSION = "0.3.51"
4
+ VERSION = "0.3.53"
5
5
  end
@@ -402,7 +402,7 @@ module Omnizip
402
402
  ::File.open(@name, "rb") do |io|
403
403
  # Find the entry in reader
404
404
  reader_entry = @reader.entries.find { |e| e.filename == entry.name }
405
- raise "Entry not found in archive: #{entry.name}" unless reader_entry
405
+ raise Errno::ENOENT, "Entry not found in archive: #{entry.name}" unless reader_entry
406
406
 
407
407
  # Extract just the data
408
408
  io.seek(reader_entry.local_header_offset, ::IO::SEEK_SET)