class IOP::ZstdCompressor

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!

@note this class depends on external zstdlib gem. @since 0.1

Public Class Methods

new(*args) click to toggle source

Creates class instance.

@param args [Array] arguments passed to Zstdlib::Deflate constructor

# File lib/iop/zstdlib.rb, line 31
def initialize(*args)
  @args = args
end

Public Instance Methods

process(data = nil) click to toggle source
Calls superclass method IOP::Sink#process
# 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!() click to toggle source
Calls superclass method IOP::Sink#process!
# File lib/iop/zstdlib.rb, line 44
def process!
  @deflate = Zstdlib::Deflate.new(*@args)
  begin
    super
  ensure
    @deflate.close
  end
end