Class: ZSTDS::Stream::Writer
- Includes:
- WriterHelpers
- Defined in:
- lib/zstds/stream/writer.rb
Constant Summary
Constants included from Delegates
Instance Attribute Summary
Attributes inherited from Abstract
#external_encoding, #internal_encoding, #io, #pos, #stat, #transcode_options
Instance Method Summary collapse
- #close ⇒ Object
- #close_nonblock(*options) ⇒ Object
- #flush ⇒ Object
- #flush_nonblock(*options) ⇒ Object
-
#initialize(destination_io, options = {}, *args) ⇒ Writer
constructor
A new instance of Writer.
- #rewind ⇒ Object
- #rewind_nonblock(*options) ⇒ Object
-
#write(*objects) ⇒ Object
– synchronous –.
-
#write_nonblock(object, *options) ⇒ Object
IO write nonblock can raise wait writable error.
Methods included from WriterHelpers
#<<, included, #print, #printf, #putc, #puts
Methods inherited from Abstract
#advise, #closed?, #set_encoding, #to_io
Methods included from Delegates
Constructor Details
#initialize(destination_io, options = {}, *args) ⇒ Writer
Returns a new instance of Writer.
13 14 15 16 17 |
# File 'lib/zstds/stream/writer.rb', line 13 def initialize(destination_io, = {}, *args) @options = super destination_io, *args end |
Instance Method Details
#close ⇒ Object
54 55 56 57 58 |
# File 'lib/zstds/stream/writer.rb', line 54 def close finish :close super end |
#close_nonblock(*options) ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/zstds/stream/writer.rb', line 111 def close_nonblock(*) return false unless finish_nonblock :close, * method(:close).super_method.call true end |
#flush ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/zstds/stream/writer.rb', line 40 def flush finish :flush @io.flush self end |
#flush_nonblock(*options) ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/zstds/stream/writer.rb', line 95 def flush_nonblock(*) return false unless finish_nonblock :flush, * @io.flush true end |
#rewind ⇒ Object
48 49 50 51 52 |
# File 'lib/zstds/stream/writer.rb', line 48 def rewind finish :close super end |
#rewind_nonblock(*options) ⇒ Object
103 104 105 106 107 108 109 |
# File 'lib/zstds/stream/writer.rb', line 103 def rewind_nonblock(*) return false unless finish_nonblock :close, * 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/zstds/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
IO write nonblock can raise wait writable error. After resolving this error user may provide same content again. It is not possible to revert accepted content after error. So we have to accept content after processing IO write nonblock. It means that first write nonblock won’t call IO write nonblock.
85 86 87 88 89 90 91 92 93 |
# File 'lib/zstds/stream/writer.rb', line 85 def write_nonblock(object, *) return 0 unless write_remaining_buffer_nonblock(*) source = transcode object.to_s bytes_written = raw_nonblock_wrapper :write, source @pos += bytes_written bytes_written end |