Adds a base64 encode wrapper, and a way to encode NBT to Base64

This commit is contained in:
zontreck 2024-05-16 13:22:05 -07:00
parent 7c194f2dd4
commit 1024c4dbd7
3 changed files with 32 additions and 1 deletions

View file

@ -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;
}
}

12
lib/utils/Converter.dart Normal file
View file

@ -0,0 +1,12 @@
import 'dart:convert';
import 'dart:typed_data';
class base64Encoder {
static String encode(List<int> value) {
return base64.encode(value);
}
static Uint8List decode(String value) {
return base64.decode(value);
}
}

View file

@ -1,6 +1,6 @@
name: libac_flutter
description: "Aria's Creations code library"
version: 1.0.3
version: 1.0.4
homepage: "https://zontreck.com"
environment: