From 0a5d99cd6f6ab3e5417585069af8f61466c9cd1c Mon Sep 17 00:00:00 2001 From: zontreck Date: Fri, 24 May 2024 15:43:47 -0700 Subject: [PATCH] File is deleted on write to ensure it does not continuously grow --- lib/nbt/SnbtIo.dart | 4 ++++ lib/nbt/Stream.dart | 2 ++ pubspec.yaml | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/nbt/SnbtIo.dart b/lib/nbt/SnbtIo.dart index b59f40f..9a74bea 100644 --- a/lib/nbt/SnbtIo.dart +++ b/lib/nbt/SnbtIo.dart @@ -7,6 +7,10 @@ import 'impl/CompoundTag.dart'; class SnbtIo { static void write(String file, CompoundTag tag) { File handle = File(file); + + if (handle.existsSync()) + handle.deleteSync(); // Ensure we flush the file to 0 bytes + StringBuilder builder = StringBuilder(); Tag.writeStringifiedNamedTag(tag, builder, 0); handle.writeAsString(builder.toString()); diff --git a/lib/nbt/Stream.dart b/lib/nbt/Stream.dart index 2a64cea..82bf471 100644 --- a/lib/nbt/Stream.dart +++ b/lib/nbt/Stream.dart @@ -210,6 +210,8 @@ class ByteLayer { Future writeToFile(String filePath) async { final file = File(filePath); + if (file.existsSync()) + file.deleteSync(); // Ensure we flush the file to 0 bytes await file.writeAsBytes(bytes); } diff --git a/pubspec.yaml b/pubspec.yaml index 79e1837..91e8c0f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: libac_dart description: "Aria's Creations code library" -version: 1.0.21 +version: 1.0.22 homepage: "https://zontreck.com"