Class: IOP::ZstdCompressor
- Inherits:
-
Object
- Object
- IOP::ZstdCompressor
- Defined in:
- lib/iop/zstdlib.rb
Overview
Note:
this class depends on external zstdlib gem.
Filter class to perform data compression with Zstandard algorithm.
This class produces valid .zst files.
### Use case: compress a string and store it to .zst file.
require 'iop/file'
require 'iop/string'
require 'iop/zstdlib'
( IOP::StringSplitter.new('Hello IOP') | IOP::ZstdCompressor.new(Zstdlib::BEST_COMPRESSION) | IOP::FileWriter.new('hello.zst') ).process!
Instance Attribute Summary
Attributes included from Sink
Attributes included from Feed
Instance Method Summary collapse
-
#initialize(*args) ⇒ ZstdCompressor
constructor
Creates class instance.
- #process(data = nil) ⇒ Object
- #process! ⇒ Object
Methods included from Feed
Constructor Details
#initialize(*args) ⇒ ZstdCompressor
Creates class instance.
31 32 33 |
# File 'lib/iop/zstdlib.rb', line 31 def initialize(*args) @args = args end |
Instance Method Details
#process(data = nil) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/iop/zstdlib.rb', line 35 def process(data = nil) if data.nil? super(@deflate.finish) super else super(@deflate.deflate(data)) end end |
#process! ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/iop/zstdlib.rb', line 44 def process! @deflate = Zstdlib::Deflate.new(*@args) begin super ensure @deflate.close end end |