Class: Snappy::Writer
- Inherits:
-
Object
- Object
- Snappy::Writer
- Defined in:
- lib/snappy/writer.rb
Constant Summary collapse
- MAGIC =
Snappy.b("\x82SNAPPY\x0")
- DEFAULT_VERSION =
1
- MINIMUM_COMPATIBLE_VERSION =
1
- DEFAULT_BLOCK_SIZE =
32 * 1024
Instance Attribute Summary collapse
-
#block_size ⇒ Object
readonly
Returns the value of attribute block_size.
-
#io ⇒ Object
readonly
Returns the value of attribute io.
Instance Method Summary collapse
- #<<(msg) ⇒ Object (also: #write)
- #close ⇒ Object
- #dump! ⇒ Object (also: #flush)
-
#initialize(io, block_size = DEFAULT_BLOCK_SIZE) ⇒ Writer
constructor
A new instance of Writer.
Constructor Details
#initialize(io, block_size = DEFAULT_BLOCK_SIZE) ⇒ Writer
Returns a new instance of Writer.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/snappy/writer.rb', line 14 def initialize(io, block_size = DEFAULT_BLOCK_SIZE) @block_size = block_size @buffer = String.new @io = Snappy.set_encoding io write_header! if block_given? yield self dump! end end |
Instance Attribute Details
#block_size ⇒ Object (readonly)
Returns the value of attribute block_size.
12 13 14 |
# File 'lib/snappy/writer.rb', line 12 def block_size @block_size end |
#io ⇒ Object (readonly)
Returns the value of attribute io.
12 13 14 |
# File 'lib/snappy/writer.rb', line 12 def io @io end |
Instance Method Details
#<<(msg) ⇒ Object Also known as: write
25 26 27 28 |
# File 'lib/snappy/writer.rb', line 25 def <<(msg) @buffer << msg.to_s dump! if @buffer.size > @block_size end |
#close ⇒ Object
41 42 43 |
# File 'lib/snappy/writer.rb', line 41 def close @io.close end |