Class: Omnizip::Algorithms::Zstandard::Encoder

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/omnizip/algorithms/zstandard/encoder.rb

Overview

Pure Ruby Zstandard encoder (RFC 8878)

Encodes data using Zstandard format. Supports raw blocks and Huffman-compressed literals.

Constant Summary

Constants included from Constants

Constants::BLOCK_HEADER_SIZE, Constants::BLOCK_MAX_SIZE, Constants::BLOCK_TYPE_COMPRESSED, Constants::BLOCK_TYPE_RAW, Constants::BLOCK_TYPE_RESERVED, Constants::BLOCK_TYPE_RLE, Constants::BUFFER_SIZE, Constants::DEFAULT_LEVEL, Constants::DEFAULT_REPEAT_OFFSETS, Constants::FSE_MAX_ACCURACY_LOG, Constants::FSE_MIN_ACCURACY_LOG, Constants::HUFFMAN_MAX_BITS, Constants::HUFFMAN_MAX_CODE_LENGTH, Constants::HUFFMAN_MAX_LOG, Constants::HUFFMAN_STANDARD_TABLE_SIZE, Constants::LITERALS_BLOCK_COMPRESSED, Constants::LITERALS_BLOCK_RAW, Constants::LITERALS_BLOCK_RLE, Constants::LITERALS_BLOCK_TREELESS, Constants::LITERALS_LENGTH_ACCURACY_LOG, Constants::LITERAL_LENGTH_TABLE, Constants::MAGIC_BYTES, Constants::MAGIC_NUMBER, Constants::MATCH_LENGTH_ACCURACY_LOG, Constants::MATCH_LENGTH_TABLE, Constants::MAX_LEVEL, Constants::MIN_LEVEL, Constants::MODE_FSE, Constants::MODE_PREDEFINED, Constants::MODE_REPEAT, Constants::MODE_RLE, Constants::OFFSET_ACCURACY_LOG, Constants::PREDEFINED_LL_DISTRIBUTION, Constants::PREDEFINED_ML_DISTRIBUTION, Constants::PREDEFINED_OFFSET_DISTRIBUTION, Constants::REPEAT_OFFSET_1, Constants::REPEAT_OFFSET_2, Constants::REPEAT_OFFSET_3, Constants::SKIPPABLE_MAGIC_BASE, Constants::SKIPPABLE_MAGIC_MASK, Constants::WINDOW_LOG_MAX, Constants::WINDOW_LOG_MIN

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output_stream, options = {}) ⇒ Encoder

Initialize encoder

Parameters:

  • output_stream (IO)

    Output stream for compressed data

  • options (Hash) (defaults to: {})

    Encoder options

Options Hash (options):

  • :level (Integer)

    Compression level (1-22)

  • :use_compression (Boolean)

    Use Huffman compression (default: true)



41
42
43
44
45
46
# File 'lib/omnizip/algorithms/zstandard/encoder.rb', line 41

def initialize(output_stream, options = {})
  @output_stream = output_stream
  @options = options
  @level = options[:level] || DEFAULT_LEVEL
  @use_compression = options.fetch(:use_compression, true)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



33
34
35
# File 'lib/omnizip/algorithms/zstandard/encoder.rb', line 33

def options
  @options
end

#output_streamObject (readonly)

Returns the value of attribute output_stream.



33
34
35
# File 'lib/omnizip/algorithms/zstandard/encoder.rb', line 33

def output_stream
  @output_stream
end

Instance Method Details

#encode_stream(data) ⇒ void

This method returns an undefined value.

Encode data stream

Parameters:

  • data (String)

    Data to compress



52
53
54
55
# File 'lib/omnizip/algorithms/zstandard/encoder.rb', line 52

def encode_stream(data)
  # Write Zstandard frame
  write_frame(data)
end