Class: ChunkWriterIO
- Inherits:
-
StringIO
- Object
- StringIO
- ChunkWriterIO
- Defined in:
- lib/neo4j/core/cypher_session/adaptors/bolt/chunk_writer_io.rb
Constant Summary collapse
- MAX_CHUNK_SIZE =
Writer for chunked data.
0xFFFF
Instance Method Summary collapse
- #buffer_result(zero_chunk = false) ⇒ Object
- #clear_buffer! ⇒ Object
-
#close(zero_chunk = false) ⇒ Object
Close the stream.
- #flush(zero_chunk = false) ⇒ Object
-
#initialize ⇒ ChunkWriterIO
constructor
A new instance of ChunkWriterIO.
-
#write_buffer!(string, size) ⇒ Object
private.
-
#write_with_chunking(string) ⇒ Object
(also: #write)
Write some bytes, splitting into chunks if necessary.
Constructor Details
#initialize ⇒ ChunkWriterIO
Returns a new instance of ChunkWriterIO.
8 9 10 11 12 |
# File 'lib/neo4j/core/cypher_session/adaptors/bolt/chunk_writer_io.rb', line 8 def initialize @output_buffer = [] @output_size = 0 super end |
Instance Method Details
#buffer_result(zero_chunk = false) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/neo4j/core/cypher_session/adaptors/bolt/chunk_writer_io.rb', line 56 def buffer_result(zero_chunk = false) result = '' # Kernel.puts 'result1', result.inspect if !@output_buffer.empty? result << [@output_size].pack('s>*') result.concat(@output_buffer.join) end # Kernel.puts 'result2', result.inspect result << "\x00\x00" if zero_chunk # Kernel.puts 'result3', result.inspect result end |
#clear_buffer! ⇒ Object
72 73 74 75 |
# File 'lib/neo4j/core/cypher_session/adaptors/bolt/chunk_writer_io.rb', line 72 def clear_buffer! @output_buffer.clear @output_size = 0 end |
#close(zero_chunk = false) ⇒ Object
Close the stream.
45 46 47 48 |
# File 'lib/neo4j/core/cypher_session/adaptors/bolt/chunk_writer_io.rb', line 45 def close(zero_chunk = false) flush(zero_chunk) super end |
#flush(zero_chunk = false) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/neo4j/core/cypher_session/adaptors/bolt/chunk_writer_io.rb', line 37 def flush(zero_chunk = false) write_without_chunking(buffer_result(zero_chunk)) clear_buffer! super() end |
#write_buffer!(string, size) ⇒ Object
private
51 52 53 54 |
# File 'lib/neo4j/core/cypher_session/adaptors/bolt/chunk_writer_io.rb', line 51 def write_buffer!(string, size) @output_buffer << string @output_size = size end |
#write_with_chunking(string) ⇒ Object Also known as: write
Write some bytes, splitting into chunks if necessary.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/neo4j/core/cypher_session/adaptors/bolt/chunk_writer_io.rb', line 15 def write_with_chunking(string) # Kernel.puts "Write!" until string.empty? future_size = @output_size + string.size if future_size >= MAX_CHUNK_SIZE last = MAX_CHUNK_SIZE - @output_size write_buffer!(string[0, last], MAX_CHUNK_SIZE) string = string[last..-1] write_without_chunking(buffer_result) clear_buffer! else write_buffer!(string, future_size) string = '' end end end |