Fix some inconsistencies
This commit is contained in:
parent
cfd97a687c
commit
4957fe633e
4 changed files with 25 additions and 15 deletions
|
@ -17,23 +17,23 @@ class NbtIo {
|
|||
}
|
||||
|
||||
// This function will read the file and check if it is infact gzipped
|
||||
static Future<CompoundTag> read(String file) async {
|
||||
static Future<Tag> read(String file) async {
|
||||
await _read(file);
|
||||
if (_io.readByte() == TagType.Compound.byte) {
|
||||
_io.resetPosition();
|
||||
return Tag.readNamedTag(_io) as CompoundTag;
|
||||
return Tag.readNamedTag(_io);
|
||||
} else {
|
||||
// Is likely gzip compressed
|
||||
return readCompressed(file);
|
||||
}
|
||||
}
|
||||
|
||||
static Future<CompoundTag> readCompressed(String file) async {
|
||||
static Future<Tag> readCompressed(String file) async {
|
||||
_io = ByteLayer();
|
||||
await _io.readFromFile(file);
|
||||
await _io.decompress();
|
||||
_io.resetPosition();
|
||||
return Tag.readNamedTag(_io) as CompoundTag;
|
||||
return Tag.readNamedTag(_io);
|
||||
}
|
||||
|
||||
static Future<void> write(String file, CompoundTag tag) async {
|
||||
|
@ -60,7 +60,7 @@ class NbtIo {
|
|||
return base64Encoder.encode(_io.bytes);
|
||||
}
|
||||
|
||||
static Future<CompoundTag> readBase64String(String encoded) async {
|
||||
static Future<Tag> readBase64String(String encoded) async {
|
||||
_io = ByteLayer();
|
||||
List<int> bytes = base64Encoder.decode(encoded);
|
||||
for (int byte in bytes) {
|
||||
|
@ -68,7 +68,7 @@ class NbtIo {
|
|||
}
|
||||
_io.decompress();
|
||||
_io.resetPosition();
|
||||
return Tag.readNamedTag(_io) as CompoundTag;
|
||||
return Tag.readNamedTag(_io);
|
||||
}
|
||||
|
||||
/// Writes the NBT Data to stream in compressed mode
|
||||
|
@ -80,7 +80,7 @@ class NbtIo {
|
|||
return _io.bytes;
|
||||
}
|
||||
|
||||
static Future<CompoundTag> readFromStreamCompressed(Uint8List list) async {
|
||||
static Future<Tag> readFromStreamCompressed(Uint8List list) async {
|
||||
_io = ByteLayer();
|
||||
try {
|
||||
_io.writeBytes(list);
|
||||
|
@ -90,7 +90,7 @@ class NbtIo {
|
|||
} catch (E) {
|
||||
print(E);
|
||||
} finally {
|
||||
return Tag.readNamedTag(_io) as CompoundTag;
|
||||
return Tag.readNamedTag(_io);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ class NbtIo {
|
|||
return _io.bytes;
|
||||
}
|
||||
|
||||
static Future<CompoundTag> readFromStream(Uint8List list) async {
|
||||
static Future<Tag> readFromStream(Uint8List list) async {
|
||||
_io = ByteLayer();
|
||||
try {
|
||||
_io.writeBytes(list);
|
||||
|
@ -109,7 +109,15 @@ class NbtIo {
|
|||
} catch (E) {
|
||||
print(E);
|
||||
} finally {
|
||||
return Tag.readNamedTag(_io) as CompoundTag;
|
||||
if (_io.readByte() == TagType.Compound.byte) {
|
||||
_io.resetPosition();
|
||||
return Tag.readNamedTag(_io);
|
||||
} else {
|
||||
_io.resetPosition();
|
||||
_io.decompress();
|
||||
_io.resetPosition();
|
||||
return Tag.readNamedTag(_io);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue