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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user