Module: BZS::Option

Defined in:
lib/bzs/option.rb

Overview

BZS::Option module.

Constant Summary collapse

DEFAULT_BUFFER_LENGTH =

Current default buffer length.

0
COMPRESSOR_DEFAULTS =

Current compressor defaults.

{
  # Enables global VM lock where possible.
  :gvl         => false,
  # Block size to be used for compression.
  :block_size  => nil,
  # Controls threshold for switching from standard to fallback algorithm.
  :work_factor => nil,
  # Disables bzip2 library logging.
  :quiet       => nil
}
.freeze
DECOMPRESSOR_DEFAULTS =

Current decompressor defaults.

{
  # Enables global VM lock where possible.
  :gvl   => false,
  # Enables alternative decompression algorithm with less memory.
  :small => nil,
  # Disables bzip2 library logging.
  :quiet => nil
}
.freeze

Class Method Summary collapse

Class Method Details

.get_compressor_options(options, buffer_length_names) ⇒ Object

Processes compressor options and buffer_length_names. Option: :source_buffer_length source buffer length. Option: :destination_buffer_length destination buffer length. Option: :gvl enables global VM lock where possible. Option: :block_size block size to be used for compression. Option: :work_factor controls threshold for switching from standard to fallback algorithm. Option: :quiet disables bzip2 library logging. Returns processed compressor options.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/bzs/option.rb', line 47

def self.get_compressor_options(options, buffer_length_names)
  Validation.validate_hash options

  buffer_length_defaults = buffer_length_names.each_with_object({}) do |name, defaults|
    defaults[name] = DEFAULT_BUFFER_LENGTH
  end

  options = COMPRESSOR_DEFAULTS.merge(buffer_length_defaults).merge options

  buffer_length_names.each { |name| Validation.validate_not_negative_integer options[name] }

  Validation.validate_bool options[:gvl]

  block_size = options[:block_size]
  Validation.validate_not_negative_integer block_size unless block_size.nil?

  work_factor = options[:work_factor]
  Validation.validate_not_negative_integer work_factor unless work_factor.nil?

  quiet = options[:quiet]
  Validation.validate_bool quiet unless quiet.nil?

  options
end

.get_decompressor_options(options, buffer_length_names) ⇒ Object

Processes decompressor options and buffer_length_names. Option: :source_buffer_length source buffer length. Option: :destination_buffer_length destination buffer length. Option: :gvl enables global VM lock where possible. Option: :small enables alternative decompression algorithm with less memory. Option: :quiet disables bzip2 library logging. Returns processed decompressor options.



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/bzs/option.rb', line 79

def self.get_decompressor_options(options, buffer_length_names)
  Validation.validate_hash options

  buffer_length_defaults = buffer_length_names.each_with_object({}) do |name, defaults|
    defaults[name] = DEFAULT_BUFFER_LENGTH
  end

  options = DECOMPRESSOR_DEFAULTS.merge(buffer_length_defaults).merge options

  buffer_length_names.each { |name| Validation.validate_not_negative_integer options[name] }

  Validation.validate_bool options[:gvl]

  small = options[:small]
  Validation.validate_bool small unless small.nil?

  quiet = options[:quiet]
  Validation.validate_bool quiet unless quiet.nil?

  options
end