class ADSP::Stream::Raw::Compressor
Constants
- BUFFER_LENGTH_NAMES
Current buffer length names. It is a part of compressor options.
- NativeCompressor
Current native compressor class.
- Option
ADSP::Option
class.
Public Class Methods
new(options = {})
click to toggle source
Initializes compressor. Option: :destination_buffer_length
destination buffer length.
Calls superclass method
ADSP::Stream::Raw::Abstract::new
# File lib/adsp/stream/raw/compressor.rb, line 27 def initialize(options = {}) options = self.class::Option.get_compressor_options options, BUFFER_LENGTH_NAMES native_stream = self.class::NativeCompressor.new options super native_stream end
Public Instance Methods
close(&writer)
click to toggle source
Finishes compressor, writes result using writer
proc and closes compressor. Raises UsedAfterCloseError
when used after close.
Calls superclass method
ADSP::Stream::Raw::Abstract#close
# File lib/adsp/stream/raw/compressor.rb, line 89 def close(&writer) return nil if closed? Validation.validate_proc writer loop do need_more_destination = @native_stream.finish if need_more_destination more_destination(&writer) next end break end super end
flush(&writer)
click to toggle source
Flushes compressor, writes result using writer
proc and closes compressor.
Calls superclass method
ADSP::Stream::Raw::Abstract#flush
# File lib/adsp/stream/raw/compressor.rb, line 68 def flush(&writer) do_not_use_after_close Validation.validate_proc writer loop do need_more_destination = @native_stream.flush if need_more_destination more_destination(&writer) next end break end super end
write(source, &writer)
click to toggle source
Writes source
string, writes result using writer
proc. Returns amount of bytes written from source
.
# File lib/adsp/stream/raw/compressor.rb, line 36 def write(source, &writer) do_not_use_after_close Validation.validate_string source Validation.validate_proc writer total_bytes_written = 0 loop do bytes_written, need_more_destination = @native_stream.write source total_bytes_written += bytes_written if need_more_destination source = source.byteslice bytes_written, source.bytesize - bytes_written more_destination(&writer) next end unless bytes_written == source.bytesize # Compressor write should eat all provided "source" without remainder. # :nocov: raise UnexpectedError, "unexpected error" # :nocov: end break end total_bytes_written end