Performance Tuning
Concepts
Excavate is designed for efficiency, but large archives or batch processing can benefit from optimization techniques.
General Tips
Use Filters
Extract only what you need:
# Slow: Extract everything
Excavate::Archive.new('large.zip').extract
# Fast: Extract only needed files
Excavate::Archive.new('large.zip').extract(filter: '**/*.txt')Recursive Extraction Optimization
Filter Early
Apply filters to reduce nested extraction:
# Optimized: Filter applied during recursive extraction
Excavate::Archive.new('installer.msi').extract(
recursive_packages: true,
filter: '**/*.dll'
)
# Slower: Extract all then filter
Excavate::Archive.new('installer.msi').extract(recursive_packages: true)
dlls = Dir.glob('installer/**/*.dll')Memory Optimization
Stream Processing
Process files without holding all in memory:
# Good: Process one file at a time
Excavate::Archive.new('large.zip').files do |path|
# Process and release
analyze_file(path)
end
# Avoid: Load all into memory
all_content = Excavate::Archive.new('large.zip').files do |path|
File.read(path) # Accumulates in memory
endDisk Space Optimization
Batch Processing
Parallel Processing
For independent archives:
require 'parallel'
archives = Dir.glob('archives/*.zip')
Parallel.each(archives, in_threads: 4) do |archive_path|
begin
Excavate::Archive.new(archive_path).extract(
filter: '**/*.txt'
)
rescue Excavate::Error => e
puts "Failed: #{archive_path} - #{e.message}"
end
endError-Resilient Batch
Continue processing after errors:
results = []
Dir.glob('archives/*').each do |archive_path|
begin
archive = Excavate::Archive.new(archive_path)
archive.extract(recursive_packages: true)
results << { path: archive_path, success: true }
rescue Excavate::Error => e
results << { path: archive_path, success: false, error: e.message }
end
end
# Report results
failed = results.reject { |r| r[:success] }
puts "Processed: #{results.size}, Failed: #{failed.size}"