Class: BRS::Stream::Writer

Inherits:
Abstract show all
Includes:
WriterHelpers
Defined in:
lib/brs/stream/writer.rb

Constant Summary

Constants included from Delegates

Delegates::DELEGATES

Instance Attribute Summary

Attributes inherited from Abstract

#external_encoding, #internal_encoding, #io, #pos, #stat, #transcode_options

Instance Method Summary collapse

Methods included from WriterHelpers

#<<, included, #print, #printf, #putc, #puts

Methods inherited from Abstract

#advise, #closed?, #set_encoding, #to_io

Methods included from Delegates

included

Constructor Details

#initialize(destination_io, options = {}, *args) ⇒ Writer

Returns a new instance of Writer.



13
14
15
16
17
# File 'lib/brs/stream/writer.rb', line 13

def initialize(destination_io, options = {}, *args)
  @options = options

  super destination_io, *args
end

Instance Method Details

#closeObject



54
55
56
57
58
# File 'lib/brs/stream/writer.rb', line 54

def close
  finish :close

  super
end

#close_nonblock(*options) ⇒ Object



106
107
108
109
110
111
112
# File 'lib/brs/stream/writer.rb', line 106

def close_nonblock(*options)
  return false unless finish_nonblock :close, *options

  method(:close).super_method.call

  true
end

#flushObject



40
41
42
43
44
45
46
# File 'lib/brs/stream/writer.rb', line 40

def flush
  finish :flush

  @io.flush

  self
end

#flush_nonblock(*options) ⇒ Object



90
91
92
93
94
95
96
# File 'lib/brs/stream/writer.rb', line 90

def flush_nonblock(*options)
  return false unless finish_nonblock :flush, *options

  @io.flush

  true
end

#rewindObject



48
49
50
51
52
# File 'lib/brs/stream/writer.rb', line 48

def rewind
  finish :close

  super
end

#rewind_nonblock(*options) ⇒ Object



98
99
100
101
102
103
104
# File 'lib/brs/stream/writer.rb', line 98

def rewind_nonblock(*options)
  return false unless finish_nonblock :close, *options

  method(:rewind).super_method.call

  true
end

#write(*objects) ⇒ Object

– synchronous –



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/brs/stream/writer.rb', line 25

def write(*objects)
  write_remaining_buffer

  bytes_written = 0

  objects.each do |object|
    source         = transcode object.to_s
    bytes_written += raw_wrapper :write, source
  end

  @pos += bytes_written

  bytes_written
end

#write_nonblock(object, *options) ⇒ Object

– asynchronous –



80
81
82
83
84
85
86
87
88
# File 'lib/brs/stream/writer.rb', line 80

def write_nonblock(object, *options)
  return 0 unless write_remaining_buffer_nonblock(*options)

  source         = transcode object.to_s
  bytes_written  = raw_nonblock_wrapper :write, source
  @pos          += bytes_written

  bytes_written
end