11import io
2- import struct
2+ from struct import unpack
33
44from ..math import Color , Matrix4x4 , Quaternion , Vector2 , Vector3 , Vector4 , Rectangle
55
@@ -36,46 +36,46 @@ def read(self, *args):
3636 return b""
3737
3838 def read_byte (self ) -> int :
39- return struct . unpack (self .endian + "b" , self .read (1 ))[0 ]
39+ return unpack (self .endian + "b" , self .read (1 ))[0 ]
4040
4141 def read_u_byte (self ) -> int :
42- return struct . unpack (self .endian + "B" , self .read (1 ))[0 ]
42+ return unpack (self .endian + "B" , self .read (1 ))[0 ]
4343
4444 def read_bytes (self , num ) -> bytes :
4545 return self .read (num )
4646
4747 def read_short (self ) -> int :
48- return struct . unpack (self .endian + "h" , self .read (2 ))[0 ]
48+ return unpack (self .endian + "h" , self .read (2 ))[0 ]
4949
5050 def read_int (self ) -> int :
51- return struct . unpack (self .endian + "i" , self .read (4 ))[0 ]
51+ return unpack (self .endian + "i" , self .read (4 ))[0 ]
5252
5353 def read_long (self ) -> int :
54- return struct . unpack (self .endian + "q" , self .read (8 ))[0 ]
54+ return unpack (self .endian + "q" , self .read (8 ))[0 ]
5555
5656 def read_u_short (self ) -> int :
57- return struct . unpack (self .endian + "H" , self .read (2 ))[0 ]
57+ return unpack (self .endian + "H" , self .read (2 ))[0 ]
5858
5959 def read_u_int (self ) -> int :
60- return struct . unpack (self .endian + "I" , self .read (4 ))[0 ]
60+ return unpack (self .endian + "I" , self .read (4 ))[0 ]
6161
6262 def read_u_long (self ) -> int :
63- return struct . unpack (self .endian + "Q" , self .read (8 ))[0 ]
63+ return unpack (self .endian + "Q" , self .read (8 ))[0 ]
6464
6565 def read_float (self ) -> float :
66- return struct . unpack (self .endian + "f" , self .read (4 ))[0 ]
66+ return unpack (self .endian + "f" , self .read (4 ))[0 ]
6767
6868 def read_double (self ) -> float :
69- return struct . unpack (self .endian + "d" , self .read (8 ))[0 ]
69+ return unpack (self .endian + "d" , self .read (8 ))[0 ]
7070
7171 def read_boolean (self ) -> bool :
72- return bool (struct . unpack (self .endian + "?" , self .read (1 ))[0 ])
72+ return bool (unpack (self .endian + "?" , self .read (1 ))[0 ])
7373
7474 def read_string (self , size = None , encoding = "utf8" ) -> str :
7575 if size is None :
7676 ret = self .read_string_to_null ()
7777 else :
78- ret = struct . unpack (f"{ self .endian } { size } is" , self .read (size ))[0 ]
78+ ret = unpack (f"{ self .endian } { size } is" , self .read (size ))[0 ]
7979 try :
8080 return ret .decode (encoding )
8181 except UnicodeDecodeError :
@@ -218,7 +218,6 @@ class EndianBinaryReader_Streamable(EndianBinaryReader):
218218
219219 def __init__ (self , stream , endian = ">" , offset = 0 ):
220220 self .stream = stream
221- self .Length = self .stream .seek (0 , 2 ) - offset
222221 super ().__init__ (stream , endian = endian , offset = offset )
223222
224223 def get_position (self ):
@@ -227,6 +226,13 @@ def get_position(self):
227226 def set_position (self , value ):
228227 self .stream .seek (value + self .BaseOffset )
229228
229+ @property
230+ def Length (self ):
231+ pos = self .Position
232+ length = self .stream .seek (0 , 2 ) - self .BaseOffset
233+ self .Position = pos
234+ return length
235+
230236 Position = property (get_position , set_position )
231237
232238 @property
0 commit comments