Class: ActiveSupport::Cache::ZstdCompressor
- Inherits:
-
Object
- Object
- ActiveSupport::Cache::ZstdCompressor
- Defined in:
- lib/active_support/cache/zstd_compressor.rb,
lib/active_support/cache/zstd_compressor/errors.rb,
lib/active_support/cache/zstd_compressor/version.rb,
lib/active_support/cache/zstd_compressor/with_zlib_fallback.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Error, NotZstdError, WithZlibFallback
Constant Summary collapse
- VERSION =
"0.2.0"
Instance Attribute Summary collapse
-
#level ⇒ Integer
readonly
Compression level.
Instance Method Summary collapse
- #deflate(inflated) ⇒ Object
- #inflate(deflated) ⇒ Object
-
#initialize(level: 3) ⇒ ZstdCompressor
constructor
A new instance of ZstdCompressor.
Constructor Details
#initialize(level: 3) ⇒ ZstdCompressor
Returns a new instance of ZstdCompressor.
17 18 19 20 21 |
# File 'lib/active_support/cache/zstd_compressor.rb', line 17 def initialize(level: 3) raise ArgumentError, "Compression level must be an Integer" unless level.is_a?(Integer) @level = level end |
Instance Attribute Details
#level ⇒ Integer (readonly)
Returns Compression level.
14 15 16 |
# File 'lib/active_support/cache/zstd_compressor.rb', line 14 def level @level end |
Instance Method Details
#deflate(inflated) ⇒ Object
23 24 25 |
# File 'lib/active_support/cache/zstd_compressor.rb', line 23 def deflate(inflated) Zstd.compress(inflated, level:) end |
#inflate(deflated) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/active_support/cache/zstd_compressor.rb', line 27 def inflate(deflated) Zstd.decompress(deflated) rescue StandardError => e # v1.5 raise NotZstdError, e. if e..include?("not compressed by zstd") # v2.0 raise NotZstdError, e. if e..include?("zstd") && e..include?("magic not found") raise end |