1
0
mirror of https://github.com/Escartem/AnimeWwise.git synced 2026-06-06 16:30:26 +08:00

slightly faster map loading

This commit is contained in:
Escartem
2024-07-23 10:14:03 +02:00
parent 9fc7bb98fb
commit 6962841ab8
2 changed files with 38 additions and 15 deletions

View File

@@ -1,3 +1,5 @@
import io
import os
import struct
@@ -60,3 +62,18 @@ class FileReader:
def SetBufferPos(self, pos:int):
self.stream.seek(pos)
def GetStreamLength(self) -> int:
if isinstance(self.stream, io.BytesIO):
return self.stream.getbuffer().nbytes
elif isinstance(self.stream, io.BufferedReader):
pos = self.GetBufferPos()
self.stream.seek(0, os.SEEK_END)
length = self.GetBufferPos()
self.SetBufferPos(pos)
return length
else:
raise Exception("unknown buffer type")
def GetRemainingLength(self) -> int:
return self.GetStreamLength() - self.GetBufferPos()