From 8caf25dd2878a743a5e051e1a200a4de566ede2a Mon Sep 17 00:00:00 2001 From: mpd Date: Wed, 22 Sep 2010 15:48:07 -0700 Subject: [PATCH] prepare for file writing. update to work with ruby 1.9.2. No longer works with 1.8, and won't in the future. --- lib/nbt/tag/byte.rb | 2 +- lib/nbt/tag/byte_array.rb | 2 +- lib/nbt/tag/compound.rb | 4 ++-- lib/nbt/tag/double.rb | 2 +- lib/nbt/tag/end.rb | 2 +- lib/nbt/tag/float.rb | 2 +- lib/nbt/tag/int.rb | 2 +- lib/nbt/tag/list.rb | 4 ++-- lib/nbt/tag/long.rb | 2 +- lib/nbt/tag/short.rb | 2 +- lib/nbt/tag/string.rb | 4 ++-- script.rb | 26 +++++++++++++------------- 12 files changed, 27 insertions(+), 27 deletions(-) diff --git a/lib/nbt/tag/byte.rb b/lib/nbt/tag/byte.rb index 0b98ff3..1590808 100644 --- a/lib/nbt/tag/byte.rb +++ b/lib/nbt/tag/byte.rb @@ -17,7 +17,7 @@ def to_s(indent = 0) (' ' * indent) + "TAG_Byte#{@name ? "(\"#{@name}\")" : ''}: #{@payload}" end - def to_nbt_string + def to_nbt_string(named = true) end end diff --git a/lib/nbt/tag/byte_array.rb b/lib/nbt/tag/byte_array.rb index 2031512..b9f67a0 100644 --- a/lib/nbt/tag/byte_array.rb +++ b/lib/nbt/tag/byte_array.rb @@ -18,7 +18,7 @@ def to_s(indent = 0) (' ' * indent) + "TAG_Byte_Array#{@name ? "(\"#{@name}\")" : ''}: [#{@payload.length} bytes]" end - def to_nbt_string + def to_nbt_string(named = true) end end diff --git a/lib/nbt/tag/compound.rb b/lib/nbt/tag/compound.rb index 7c5cb1b..fe019b5 100644 --- a/lib/nbt/tag/compound.rb +++ b/lib/nbt/tag/compound.rb @@ -8,7 +8,7 @@ def initialize(io, named = true) @tag_names = [] read_name(io) if named - until (last_byte = io.read(1)[0]) == NBT::Tag::End.type_id + until (last_byte = io.read(1).bytes.first) == NBT::Tag::End.type_id klass = tag_type_to_class(last_byte) i = klass.new(io, true) add_tag(i) @@ -30,7 +30,7 @@ def to_s(indent = 0) ret end - def to_nbt_string + def to_nbt_string(named = true) end diff --git a/lib/nbt/tag/double.rb b/lib/nbt/tag/double.rb index d44b689..5599f54 100644 --- a/lib/nbt/tag/double.rb +++ b/lib/nbt/tag/double.rb @@ -17,7 +17,7 @@ def to_s(indent = 0) (' ' * indent) + "TAG_Double#{@name ? "(\"#{@name}\")" : ''}: #{@payload}" end - def to_nbt_string + def to_nbt_string(named = true) end end diff --git a/lib/nbt/tag/end.rb b/lib/nbt/tag/end.rb index 16ff796..4e8aeb5 100644 --- a/lib/nbt/tag/end.rb +++ b/lib/nbt/tag/end.rb @@ -15,7 +15,7 @@ def to_s(indent = 0) '' end - def to_nbt_string + def to_nbt_string(named = true) end end diff --git a/lib/nbt/tag/float.rb b/lib/nbt/tag/float.rb index e8bcd2d..0ce1538 100644 --- a/lib/nbt/tag/float.rb +++ b/lib/nbt/tag/float.rb @@ -17,7 +17,7 @@ def to_s(indent = 0) (' ' * indent) + "TAG_Float#{@name ? "(\"#{@name}\")" : ''}: #{@payload}" end - def to_nbt_string + def to_nbt_string(named = true) end end diff --git a/lib/nbt/tag/int.rb b/lib/nbt/tag/int.rb index e01aa39..9e2ec6f 100644 --- a/lib/nbt/tag/int.rb +++ b/lib/nbt/tag/int.rb @@ -17,7 +17,7 @@ def to_s(indent = 0) (' ' * indent) + "TAG_Int#{@name ? "(\"#{@name}\")" : ''}: #{@payload}" end - def to_nbt_string + def to_nbt_string(named = true) end end diff --git a/lib/nbt/tag/list.rb b/lib/nbt/tag/list.rb index 513e57b..8b33a21 100644 --- a/lib/nbt/tag/list.rb +++ b/lib/nbt/tag/list.rb @@ -7,7 +7,7 @@ def initialize(io, named = true) @payload = [] read_name(io) if named - tag_id = io.read(1)[0].to_i + tag_id = io.read(1).bytes.first.to_i @tag_type = NBT::Tag.tag_type_to_class(tag_id) len = ::BinData::Int32be.new.read(io).value len.times do @@ -30,7 +30,7 @@ def to_s(indent = 0) ret end - def to_nbt_string + def to_nbt_string(named = true) end end diff --git a/lib/nbt/tag/long.rb b/lib/nbt/tag/long.rb index 69ed3b2..141ff48 100644 --- a/lib/nbt/tag/long.rb +++ b/lib/nbt/tag/long.rb @@ -17,7 +17,7 @@ def to_s(indent = 0) (' ' * indent) + "TAG_Long#{@name ? "(\"#{@name}\")" : ''}: #{@payload}" end - def to_nbt_string + def to_nbt_string(named = true) end end diff --git a/lib/nbt/tag/short.rb b/lib/nbt/tag/short.rb index 8f2a799..a982fe7 100644 --- a/lib/nbt/tag/short.rb +++ b/lib/nbt/tag/short.rb @@ -17,7 +17,7 @@ def to_s(indent = 0) (' ' * indent) + "TAG_Short#{@name ? "(\"#{@name}\")" : ''}: #{@payload}" end - def to_nbt_string + def to_nbt_string(named = true) end end diff --git a/lib/nbt/tag/string.rb b/lib/nbt/tag/string.rb index c12fe31..0b874c2 100644 --- a/lib/nbt/tag/string.rb +++ b/lib/nbt/tag/string.rb @@ -6,7 +6,7 @@ class String def initialize(io, named = true) read_name(io) if named - l = io.read(2).unpack('n').first + l = ::BinData::Int16be.new.read(io).value.to_i @payload = io.read(l) end @@ -19,7 +19,7 @@ def to_s(indent = 0) (' ' * indent) + "TAG_String#{@name ? "(\"#{@name}\")" : ''}: #{@payload}" end - def to_nbt_string + def to_nbt_string(named = true) end end diff --git a/script.rb b/script.rb index a4a7f64..ec2ec6c 100644 --- a/script.rb +++ b/script.rb @@ -1,7 +1,7 @@ require 'bundler' Bundler.require :default -require 'lib/nbt' +require File.expand_path('./lib/nbt', File.dirname(__FILE__)) require 'zlib' # Strangely, both test files have an extra null at the end of them, which would be a @@ -9,20 +9,20 @@ @compound = nil -#Zlib::GzipReader.open('test.nbt') do |f| -# # ostensibly this will always be a single TAG_Compound, per the spec -# last_byte = f.read(1)[0] -# klass = NBT::Tag.tag_type_to_class(last_byte) -# -# @compound = klass.new(f, true) -#end -# -#puts @compound.to_s -#puts +Zlib::GzipReader.open('doc/test.nbt') do |f| + # ostensibly this will always be a single TAG_Compound, per the spec + last_byte = f.read(1).bytes.first + klass = NBT::Tag.tag_type_to_class(last_byte) + + @compound = klass.new(f, true) +end + +puts @compound.to_s +puts Zlib::GzipReader.open('doc/bigtest.nbt') do |f| # ostensibly this will always be a single TAG_Compound, per the spec - last_byte = f.read(1)[0] + last_byte = f.read(1).bytes.first klass = NBT::Tag.tag_type_to_class(last_byte) @compound = klass.new(f, true) @@ -30,6 +30,6 @@ puts @compound.to_s -#puts @compound.find_tag('Test') +puts @compound.find_tag('Test') puts @compound.find_tags(/(?:byte|int)Test/) puts @compound.find_tags 'intasdf' \ No newline at end of file