Fix: Write locking on windows

On windows this write lock seems to persist even after writing has completed, so we switch to a Random Access File instead by opening then closing the file when done reading or writing to it.
This commit is contained in:
zontreck 2024-11-25 11:57:59 -07:00
parent 1882e19289
commit d7cc626144
3 changed files with 22 additions and 6 deletions

View file

@ -1,3 +1,3 @@
class Constants {
static const VERSION = "1.2.090324+0325";
static const VERSION = "1.2.112524+1156";
}

View file

@ -214,9 +214,21 @@ class ByteLayer {
Future<void> 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);
try {
if (file.existsSync())
file.deleteSync(); // Ensure we flush the file to 0 bytes
} catch (E) {
// If it fails then it fails, just fail silently, writing should still succeed.
}
var rac = await file.open(mode: FileMode.write);
for (var byte in bytes) {
await rac.writeByte(byte);
}
await rac.flush();
await rac.close();
}
Future<void> readFromFile(String filePath) async {
@ -227,7 +239,11 @@ class ByteLayer {
return;
}
_byteBuffer = await file.readAsBytes();
RandomAccessFile rac = await file.open(mode: FileMode.read);
var length = await rac.length();
_byteBuffer = await rac.read(length);
await rac.close();
resetPosition();
}