Class: NBTUtils::File
- Inherits:
-
Object
- Object
- NBTUtils::File
- Defined in:
- lib/nbt_utils/file.rb
Instance Method Summary (collapse)
-
- (File) initialize(path = nil)
constructor
A new instance of File.
- - (Object) read(path = @path)
- - (Object) write(path = @path, tag = @tag)
Constructor Details
- (File) initialize(path = nil)
A new instance of File
3 4 5 |
# File 'lib/nbt_utils/file.rb', line 3 def initialize(path = nil) @path = path end |
Instance Method Details
- (Object) read(path = @path)
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/nbt_utils/file.rb', line 7 def read(path = @path) Zlib::GzipReader.open(path) do |f| @content = StringIO.new(f.read) end last_byte = @content.read(1).bytes.first klass = NBTUtils::Tag.tag_type_to_class(last_byte) @tag = klass.new(@content, true) end |
- (Object) write(path = @path, tag = @tag)
18 19 20 21 22 |
# File 'lib/nbt_utils/file.rb', line 18 def write(path = @path, tag = @tag) Zlib::GzipWriter.open(path) do |gz| gz.write tag.to_nbt_string end end |