Class: NBTFile::Writer
Instance Method Summary collapse
- #emit_compound(name) ⇒ Object
- #emit_item(value) ⇒ Object
- #emit_list(name, type) ⇒ Object
- #emit_token(token) ⇒ Object
- #finish ⇒ Object
-
#initialize(stream) ⇒ Writer
constructor
A new instance of Writer.
Constructor Details
#initialize(stream) ⇒ Writer
Returns a new instance of Writer.
478 479 480 481 |
# File 'lib/nbtfile.rb', line 478 def initialize(stream) @gz = Zlib::GzipWriter.new(stream) @state = TopWriterState.new() end |
Instance Method Details
#emit_compound(name) ⇒ Object
487 488 489 490 491 492 493 494 |
# File 'lib/nbtfile.rb', line 487 def emit_compound(name) emit_token(TAG_Compound[name, nil]) begin yield ensure emit_token(TAG_End[nil, nil]) end end |
#emit_item(value) ⇒ Object
505 506 507 |
# File 'lib/nbtfile.rb', line 505 def emit_item(value) @state = @state.emit_item(@gz, value) end |
#emit_list(name, type) ⇒ Object
496 497 498 499 500 501 502 503 |
# File 'lib/nbtfile.rb', line 496 def emit_list(name, type) emit_token(TAG_List[name, type]) begin yield ensure emit_token(TAG_End[nil, nil]) end end |
#emit_token(token) ⇒ Object
483 484 485 |
# File 'lib/nbtfile.rb', line 483 def emit_token(token) @state = @state.emit_token(@gz, token) end |
#finish ⇒ Object
509 510 511 |
# File 'lib/nbtfile.rb', line 509 def finish @gz.close end |