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.
480 481 482 483 |
# File 'lib/nbtfile.rb', line 480 def initialize(stream) @gz = Zlib::GzipWriter.new(stream) @state = TopWriterState.new() end |
Instance Method Details
#emit_compound(name) ⇒ Object
489 490 491 492 493 494 495 496 |
# File 'lib/nbtfile.rb', line 489 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
507 508 509 |
# File 'lib/nbtfile.rb', line 507 def emit_item(value) @state = @state.emit_item(@gz, value) end |
#emit_list(name, type) ⇒ Object
498 499 500 501 502 503 504 505 |
# File 'lib/nbtfile.rb', line 498 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
485 486 487 |
# File 'lib/nbtfile.rb', line 485 def emit_token(token) @state = @state.emit_token(@gz, token) end |
#finish ⇒ Object
511 512 513 |
# File 'lib/nbtfile.rb', line 511 def finish @gz.close end |