Class: ADSP::Stream::Raw::Decompressor
- Defined in:
- lib/adsp/stream/raw/decompressor.rb
Overview
ADSP::Stream::Raw::Decompressor class.
Direct Known Subclasses
Constant Summary collapse
- NativeDecompressor =
Current native decompressor class.
Raw::NativeDecompressor
- Option =
Current option class.
ADSP::Option
- BUFFER_LENGTH_NAMES =
Current buffer length names. It is a part of decompressor options.
%i[destination_buffer_length].freeze
Instance Method Summary collapse
-
#close(&writer) ⇒ Object
Writes result using
writer
proc and closes decompressor. -
#flush(&writer) ⇒ Object
Flushes decompressor, writes result using
writer
proc and closes decompressor. -
#initialize(options = {}) ⇒ Decompressor
constructor
Initializes decompressor.
-
#read(source, &writer) ⇒ Object
Reads
source
string, writes result usingwriter
proc.
Methods inherited from Abstract
Constructor Details
#initialize(options = {}) ⇒ Decompressor
Initializes decompressor. Option: :destination_buffer_length
destination buffer length.
26 27 28 29 30 31 |
# File 'lib/adsp/stream/raw/decompressor.rb', line 26 def initialize( = {}) = self.class::Option. , BUFFER_LENGTH_NAMES native_stream = self.class::NativeDecompressor.new super native_stream end |
Instance Method Details
#close(&writer) ⇒ Object
Writes result using writer
proc and closes decompressor. Raises UsedAfterCloseError
when used after close.
70 71 72 73 74 75 76 |
# File 'lib/adsp/stream/raw/decompressor.rb', line 70 def close(&writer) return nil if closed? Validation.validate_proc writer super end |
#flush(&writer) ⇒ Object
Flushes decompressor, writes result using writer
proc and closes decompressor.
60 61 62 63 64 65 66 |
# File 'lib/adsp/stream/raw/decompressor.rb', line 60 def flush(&writer) do_not_use_after_close Validation.validate_proc writer super end |
#read(source, &writer) ⇒ Object
Reads source
string, writes result using writer
proc. Returns amount of bytes read from source
.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/adsp/stream/raw/decompressor.rb', line 35 def read(source, &writer) do_not_use_after_close Validation.validate_string source Validation.validate_proc writer total_bytes_read = 0 loop do bytes_read, need_more_destination = @native_stream.read source total_bytes_read += bytes_read if need_more_destination source = source.byteslice bytes_read, source.bytesize - bytes_read more_destination(&writer) next end break end total_bytes_read end |