Class: Snappy::Writer
- Inherits:
-
Object
- Object
- Snappy::Writer
- Defined in:
- lib/snappy/writer.rb
Constant Summary collapse
- MAGIC =
"\x82SNAPPY\x0".force_encoding Encoding::ASCII_8BIT
- 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 24 |
# File 'lib/snappy/writer.rb', line 14 def initialize(io, block_size = DEFAULT_BLOCK_SIZE) @block_size = block_size @buffer = "" @io = io @io.set_encoding Encoding::ASCII_8BIT unless RUBY_VERSION =~ /^1\.8/ 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
26 27 28 29 |
# File 'lib/snappy/writer.rb', line 26 def <<(msg) @buffer << msg.to_s dump! if @buffer.size > @block_size end |
#close ⇒ Object
42 43 44 |
# File 'lib/snappy/writer.rb', line 42 def close @io.close end |