nbt_utils 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/Gemfile.lock +2 -2
- data/README.md +7 -5
- data/doc/bigtest_uncompressed.nbt +0 -0
- data/doc/test_uncompressed.nbt +0 -0
- data/lib/nbt_utils/file.rb +23 -5
- data/lib/nbt_utils/tag.rb +2 -5
- data/lib/nbt_utils/tag/byte_array.rb +1 -1
- data/lib/nbt_utils/tag/int_array.rb +35 -0
- data/lib/nbt_utils/version.rb +1 -1
- data/nbt_utils.gemspec +2 -2
- metadata +50 -52
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c47cdd430f8c7666f68f40f505c7644efbad37aa
|
4
|
+
data.tar.gz: 75efc43db2901b025bd1ff8e834e235abd9fb0a7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 743f9440efcf013105f404653893f85e26fbb5f81705077e3df36a32276b9cdfd04447dbf633b2dbc53714af0639ff95681c908fb0537bea7cb160c618ec6bd9
|
7
|
+
data.tar.gz: 4fd80a295519ec8d825f9b091d0d0c785a83f2d3029f4ac5de464ba2dacddc7ee5a6db552aa54b1a535b21435c4d4cae3254e52e311061920aa0584aaf192f15
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -3,12 +3,12 @@ nbt_utils
|
|
3
3
|
|
4
4
|
Some classes for handling [Minecraft](http://minecraft.net) .nbt files.
|
5
5
|
|
6
|
-
See
|
6
|
+
See the spec (NBT.txt in doc directory) for more info.
|
7
7
|
|
8
8
|
Installation
|
9
9
|
============
|
10
10
|
|
11
|
-
Requires ruby 1.9 minimum. Tested with 1.9.2
|
11
|
+
Requires ruby 1.9 minimum. Tested with 1.9.2+
|
12
12
|
|
13
13
|
gem install nbt_utils
|
14
14
|
|
@@ -19,12 +19,14 @@ Use
|
|
19
19
|
|
20
20
|
require 'nbt_utils'
|
21
21
|
|
22
|
-
@
|
22
|
+
@file = NBTUtils::File.new
|
23
|
+
@tag = @file.read('some_nbt_file.nbt')
|
23
24
|
puts @tag.to_s
|
25
|
+
@file.write('some_path.nbt', @tag, <compress? true/false>)
|
24
26
|
|
25
27
|
Copyright
|
26
28
|
=========
|
27
29
|
|
28
|
-
Copyright (c) 2010 Michael Dungan, mpd@jesters-court.net, released under the MIT license.
|
30
|
+
Copyright (c) 2010-2015 Michael Dungan, mpd@jesters-court.net, released under the MIT license.
|
29
31
|
|
30
|
-
The files `NBT.txt`, `test.nbt`,
|
32
|
+
The files `NBT.txt`, `test.nbt`, `test_uncompressed.nbt`, `bigtest.nbt`, and `bigtest_uncompressed.nbt` in the doc directory are mirrored from the Minecraft website and not covered under the above license.
|
Binary file
|
Binary file
|
data/lib/nbt_utils/file.rb
CHANGED
@@ -5,19 +5,37 @@ module NBTUtils
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def read(path = @path)
|
8
|
-
Zlib
|
9
|
-
|
8
|
+
# Zlib does not provide a way to test a file for compressed, and I'm
|
9
|
+
# not going to tool around with magic numbers, so I guess we use
|
10
|
+
# exceptions for flow control.
|
11
|
+
begin
|
12
|
+
Zlib::GzipReader.open(path) do |f|
|
13
|
+
@content = StringIO.new(f.read)
|
14
|
+
end
|
15
|
+
@compressed = true
|
16
|
+
rescue Zlib::GzipFile::Error
|
17
|
+
::File.open(path) do |f|
|
18
|
+
@content = StringIO.new(f.read)
|
19
|
+
end
|
20
|
+
@compressed = false
|
10
21
|
end
|
11
22
|
|
23
|
+
|
12
24
|
last_byte = @content.read(1).bytes.first
|
13
25
|
klass = NBTUtils::Tag.tag_type_to_class(last_byte)
|
14
26
|
|
15
27
|
@tag = klass.new(@content, true)
|
16
28
|
end
|
17
29
|
|
18
|
-
def write(path = @path, tag = @tag)
|
19
|
-
|
20
|
-
|
30
|
+
def write(path = @path, tag = @tag, compressed = @compressed)
|
31
|
+
if compressed
|
32
|
+
Zlib::GzipWriter.open(path) do |gz|
|
33
|
+
gz.write tag.to_nbt_string
|
34
|
+
end
|
35
|
+
else
|
36
|
+
::File.open(path, 'w') do |f|
|
37
|
+
f.write tag.to_nbt_string
|
38
|
+
end
|
21
39
|
end
|
22
40
|
end
|
23
41
|
end
|
data/lib/nbt_utils/tag.rb
CHANGED
@@ -17,10 +17,7 @@ module NBTUtils
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def binary_type_id
|
20
|
-
|
21
|
-
byte = ::BinData::Int8be.new
|
22
|
-
byte.value = type_id
|
23
|
-
byte.to_binary_s
|
20
|
+
type_id.chr
|
24
21
|
end
|
25
22
|
|
26
23
|
def to_s(indent = 0)
|
@@ -78,4 +75,4 @@ module NBTUtils
|
|
78
75
|
@tag_types[index] = tag_type
|
79
76
|
end
|
80
77
|
end
|
81
|
-
end
|
78
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module NBTUtils
|
2
|
+
module Tag
|
3
|
+
class IntArray
|
4
|
+
include NBTUtils::Tag
|
5
|
+
|
6
|
+
type_id 11
|
7
|
+
|
8
|
+
def initialize(io, named = true)
|
9
|
+
read_name(io) if named
|
10
|
+
|
11
|
+
len = ::BinData::Int32be.new.read(io).value
|
12
|
+
|
13
|
+
@payload = ::BinData::Array.new(:type => :int32be, :initial_length => len).read(io)
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s(indent = 0)
|
17
|
+
(' ' * indent) + "TAG_Int_Array#{@name ? "(\"#{@name}\")" : ''}: [#{@payload.length} bytes]"
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_nbt_string(named = true)
|
21
|
+
result = named ? binary_type_id + name_to_nbt_string : ''
|
22
|
+
len = ::BinData::Int32be.new
|
23
|
+
len.value = @payload.length
|
24
|
+
result << len.to_binary_s
|
25
|
+
result + @payload.to_binary_s
|
26
|
+
end
|
27
|
+
|
28
|
+
def set_value(new_value, index)
|
29
|
+
b = ::BinData::Int32be.new
|
30
|
+
b.value = new_value
|
31
|
+
@payload[index] = b.to_binary_s
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/nbt_utils/version.rb
CHANGED
data/nbt_utils.gemspec
CHANGED
@@ -14,9 +14,9 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.required_rubygems_version = ">= 1.3.6"
|
15
15
|
|
16
16
|
s.add_dependency "bindata", "~> 1.3"
|
17
|
-
s.add_development_dependency "bundler", "
|
17
|
+
s.add_development_dependency "bundler", "~> 1"
|
18
18
|
|
19
|
-
s.required_ruby_version = "
|
19
|
+
s.required_ruby_version = ">= 1.9"
|
20
20
|
|
21
21
|
s.files = `git ls-files`.split("\n")
|
22
22
|
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
metadata
CHANGED
@@ -1,59 +1,62 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: nbt_utils
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 0.0.3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
6
5
|
platform: ruby
|
7
|
-
authors:
|
6
|
+
authors:
|
8
7
|
- Michael Dungan
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
dependencies:
|
16
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2015-03-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
17
14
|
name: bindata
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version: "1.3"
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
25
20
|
type: :runtime
|
26
|
-
version_requirements: *id001
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: bundler
|
29
21
|
prerelease: false
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1'
|
36
34
|
type: :development
|
37
|
-
|
38
|
-
|
39
|
-
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1'
|
41
|
+
description: Some classes to read and write Minecraft .nbt files. See http://www.minecraft.net/docs/NBT.txt
|
42
|
+
for format description.
|
43
|
+
email:
|
40
44
|
- mpd@jesters-court.net
|
41
45
|
executables: []
|
42
|
-
|
43
46
|
extensions: []
|
44
|
-
|
45
47
|
extra_rdoc_files: []
|
46
|
-
|
47
|
-
|
48
|
-
- .gitignore
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
49
50
|
- Gemfile
|
50
51
|
- Gemfile.lock
|
51
52
|
- README.md
|
52
53
|
- Rakefile
|
53
54
|
- doc/NBT.txt
|
54
55
|
- doc/bigtest.nbt
|
56
|
+
- doc/bigtest_uncompressed.nbt
|
55
57
|
- doc/test.mclevel
|
56
58
|
- doc/test.nbt
|
59
|
+
- doc/test_uncompressed.nbt
|
57
60
|
- lib/nbt_utils.rb
|
58
61
|
- lib/nbt_utils/file.rb
|
59
62
|
- lib/nbt_utils/tag.rb
|
@@ -65,6 +68,7 @@ files:
|
|
65
68
|
- lib/nbt_utils/tag/exceptions.rb
|
66
69
|
- lib/nbt_utils/tag/float.rb
|
67
70
|
- lib/nbt_utils/tag/int.rb
|
71
|
+
- lib/nbt_utils/tag/int_array.rb
|
68
72
|
- lib/nbt_utils/tag/list.rb
|
69
73
|
- lib/nbt_utils/tag/long.rb
|
70
74
|
- lib/nbt_utils/tag/short.rb
|
@@ -73,33 +77,27 @@ files:
|
|
73
77
|
- lib/nbt_utils/version.rb
|
74
78
|
- nbt_utils.gemspec
|
75
79
|
- script.rb
|
76
|
-
has_rdoc: true
|
77
80
|
homepage: https://github.com/xxx/nbt_utils
|
78
81
|
licenses: []
|
79
|
-
|
82
|
+
metadata: {}
|
80
83
|
post_install_message:
|
81
84
|
rdoc_options: []
|
82
|
-
|
83
|
-
require_paths:
|
85
|
+
require_paths:
|
84
86
|
- lib
|
85
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
none: false
|
93
|
-
requirements:
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '1.9'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
94
|
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
95
|
+
- !ruby/object:Gem::Version
|
96
96
|
version: 1.3.6
|
97
97
|
requirements: []
|
98
|
-
|
99
98
|
rubyforge_project:
|
100
|
-
rubygems_version:
|
99
|
+
rubygems_version: 2.2.2
|
101
100
|
signing_key:
|
102
|
-
specification_version:
|
101
|
+
specification_version: 4
|
103
102
|
summary: Set of classes to read and write Minecraft .nbt files
|
104
103
|
test_files: []
|
105
|
-
|