Class: ADSP::Stream::Abstract
- Inherits:
-
Object
- Object
- ADSP::Stream::Abstract
- Includes:
- Delegates
- Defined in:
- lib/adsp/stream/abstract.rb
Overview
ADSP::Stream::Abstract class.
Constant Summary
Constants included from Delegates
Instance Attribute Summary collapse
-
#external_encoding ⇒ Object
readonly
Encoding name for destination data.
-
#internal_encoding ⇒ Object
readonly
Encoding name for source data.
-
#io ⇒ Object
readonly
Native stream.
-
#pos ⇒ Object
(also: #tell)
readonly
Current offset for source data.
-
#stat ⇒ Object
readonly
Native stream status info.
-
#transcode_options ⇒ Object
readonly
Transcode options for native stream.
Instance Method Summary collapse
-
#advise ⇒ Object
Sets access mode for native stream, noop.
-
#close ⇒ Object
Closes stream.
-
#closed? ⇒ Boolean
Returns whether stream is closed.
-
#initialize(io, options = {}) ⇒ Abstract
constructor
Initializes stream using
io
native stream andoptions
. -
#rewind ⇒ Object
Resets stream and source position.
-
#set_encoding(*args) ⇒ Object
Sets encoding for source and destination data.
-
#to_io ⇒ Object
Returns self object.
Methods included from Delegates
Constructor Details
#initialize(io, options = {}) ⇒ Abstract
Initializes stream using io
native stream and options
. Option: :external_encoding
encoding name for destination data. Option: :internal_encoding
encoding name for source data. Option: :transcode_options
transcode options for data.
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/adsp/stream/abstract.rb', line 46 def initialize(io, = {}) @raw_stream = create_raw_stream @io = io @stat = Stat.new @io.stat if @io.respond_to? :stat set_encoding [:external_encoding], [:internal_encoding], [:transcode_options] reset_buffer reset_io_advise @pos = 0 end |
Instance Attribute Details
#external_encoding ⇒ Object (readonly)
Encoding name for destination data.
30 31 32 |
# File 'lib/adsp/stream/abstract.rb', line 30 def external_encoding @external_encoding end |
#internal_encoding ⇒ Object (readonly)
Encoding name for source data.
33 34 35 |
# File 'lib/adsp/stream/abstract.rb', line 33 def internal_encoding @internal_encoding end |
#io ⇒ Object (readonly)
Native stream.
24 25 26 |
# File 'lib/adsp/stream/abstract.rb', line 24 def io @io end |
#pos ⇒ Object (readonly) Also known as: tell
Current offset for source data.
39 40 41 |
# File 'lib/adsp/stream/abstract.rb', line 39 def pos @pos end |
#stat ⇒ Object (readonly)
Native stream status info.
27 28 29 |
# File 'lib/adsp/stream/abstract.rb', line 27 def stat @stat end |
#transcode_options ⇒ Object (readonly)
Transcode options for native stream.
36 37 38 |
# File 'lib/adsp/stream/abstract.rb', line 36 def @transcode_options end |
Instance Method Details
#advise ⇒ Object
Sets access mode for native stream, noop.
86 87 88 89 |
# File 'lib/adsp/stream/abstract.rb', line 86 def advise # Noop nil end |
#close ⇒ Object
Closes stream.
183 184 185 186 187 |
# File 'lib/adsp/stream/abstract.rb', line 183 def close @io.close if @io.respond_to? :close nil end |
#closed? ⇒ Boolean
Returns whether stream is closed.
190 191 192 193 194 195 196 197 198 |
# File 'lib/adsp/stream/abstract.rb', line 190 def closed? return false unless @raw_stream.closed? if @io.respond_to? :closed @io.closed? else true end end |
#rewind ⇒ Object
Resets stream and source position. Returns zero (offset for source data).
169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/adsp/stream/abstract.rb', line 169 def rewind @raw_stream = create_raw_stream @io.rewind if @io.respond_to? :rewind reset_buffer reset_io_advise @pos = 0 0 end |
#set_encoding(*args) ⇒ Object
Sets encoding for source and destination data. First argument: :external_encoding
encoding name for destination data. Second argument: :internal_encoding
encoding name for source data. Third argument: :transcode_options
transcode options for data.
97 98 99 100 101 102 103 104 105 |
# File 'lib/adsp/stream/abstract.rb', line 97 def set_encoding(*args) external_encoding, internal_encoding, = process_set_encoding_arguments(*args) set_target_encoding :@external_encoding, external_encoding set_target_encoding :@internal_encoding, internal_encoding @transcode_options = self end |
#to_io ⇒ Object
Returns self object.
201 202 203 |
# File 'lib/adsp/stream/abstract.rb', line 201 def to_io self end |