Adds a base64 encode wrapper, and a way to encode NBT to Base64
This commit is contained in:
parent
7c194f2dd4
commit
1024c4dbd7
3 changed files with 32 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
|||
import 'package:libac_flutter/nbt/Stream.dart';
|
||||
import 'package:libac_flutter/nbt/Tag.dart';
|
||||
import 'package:libac_flutter/nbt/impl/CompoundTag.dart';
|
||||
import 'package:libac_flutter/utils/Converter.dart';
|
||||
|
||||
class NbtIo {
|
||||
static ByteLayer _io = ByteLayer();
|
||||
|
@ -49,4 +50,22 @@ class NbtIo {
|
|||
static ByteLayer getStream() {
|
||||
return _io;
|
||||
}
|
||||
|
||||
static Future<String> writeBase64String(CompoundTag tag) async {
|
||||
_io = ByteLayer();
|
||||
Tag.writeNamedTag(tag, _io);
|
||||
_io.compress();
|
||||
return base64Encoder.encode(_io.bytes);
|
||||
}
|
||||
|
||||
static Future<CompoundTag> readBase64String(String encoded) async {
|
||||
_io = ByteLayer();
|
||||
List<int> bytes = base64Encoder.decode(encoded);
|
||||
for (int byte in bytes) {
|
||||
_io.writeByte(byte);
|
||||
}
|
||||
_io.decompress();
|
||||
_io.resetPosition();
|
||||
return Tag.readNamedTag(_io) as CompoundTag;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue