Class: Omnizip::Filter Abstract
- Inherits:
-
Object
- Object
- Omnizip::Filter
- Defined in:
- lib/omnizip/filter.rb
Overview
Subclasses must implement encode, decode, metadata
Abstract base class for all preprocessing filters
Filters are reversible transformations applied to data before compression to improve compression ratios. This class defines the interface that all filter implementations must follow.
The key innovation is format-aware ID resolution: different formats (7z, XZ) use different IDs for the same filter. This class provides the id_for_format(format) method to handle this mapping.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#architecture ⇒ Symbol?
readonly
Architecture identifier (:x86, :arm, :arm64, :powerpc, :ia64, :sparc) or nil for architecture-agnostic filters.
-
#name ⇒ String
readonly
Human-readable filter name.
Class Method Summary collapse
-
.metadata ⇒ Hash
Get metadata about this filter.
Instance Method Summary collapse
-
#decode(data, position = 0) ⇒ String
Decode (postprocess) data after decompression.
-
#encode(data, position = 0) ⇒ String
Encode (preprocess) data for compression.
-
#id_for_format(format) ⇒ Integer
Get filter ID for specific format.
-
#initialize(architecture: nil, name: "Unknown") ⇒ Filter
constructor
Initialize filter.
Constructor Details
#initialize(architecture: nil, name: "Unknown") ⇒ Filter
Initialize filter
72 73 74 75 |
# File 'lib/omnizip/filter.rb', line 72 def initialize(architecture: nil, name: "Unknown") @architecture = architecture @name = name end |
Instance Attribute Details
#architecture ⇒ Symbol? (readonly)
Returns Architecture identifier (:x86, :arm, :arm64, :powerpc, :ia64, :sparc) or nil for architecture-agnostic filters.
62 63 64 |
# File 'lib/omnizip/filter.rb', line 62 def architecture @architecture end |
#name ⇒ String (readonly)
Returns Human-readable filter name.
65 66 67 |
# File 'lib/omnizip/filter.rb', line 65 def name @name end |
Class Method Details
.metadata ⇒ Hash
Get metadata about this filter
135 136 137 138 |
# File 'lib/omnizip/filter.rb', line 135 def raise NotImplementedError, "#{self} must implement .metadata" end |
Instance Method Details
#decode(data, position = 0) ⇒ String
Decode (postprocess) data after decompression
Reverses the encoding transformation, restoring original data.
118 119 120 121 |
# File 'lib/omnizip/filter.rb', line 118 def decode(data, position = 0) raise NotImplementedError, "#{self.class} must implement #decode(data, position)" end |
#encode(data, position = 0) ⇒ String
Encode (preprocess) data for compression
Transforms data to make it more compressible. The transformation must be reversible - decode(encode(data)) == data.
105 106 107 108 |
# File 'lib/omnizip/filter.rb', line 105 def encode(data, position = 0) raise NotImplementedError, "#{self.class} must implement #encode(data, position)" end |
#id_for_format(format) ⇒ Integer
Get filter ID for specific format
This is the KEY METHOD that solves the filter ID mapping problem. Different formats (7z, XZ) use different IDs for the same filter.
91 92 93 94 |
# File 'lib/omnizip/filter.rb', line 91 def id_for_format(format) raise NotImplementedError, "#{self.class} must implement #id_for_format(format)" end |