@@ -68,7 +68,8 @@ def __init__(self, file):
6868 self .lo_masks_inv = [0x00 , 0x80 , 0xC0 , 0xE0 , 0xF0 , 0xF8 , 0xFC , 0xFE , 0xFF ]
6969 self .hi_masks = [0xFF ^ mask for mask in self .lo_masks ]
7070 self .hi_masks_inv = [0xFF ^ mask for mask in self .lo_masks_inv ]
71-
71+
72+ self .read_basic = self .io .read
7273 '''
7374 Additional Properties
7475 '''
@@ -88,9 +89,9 @@ def reset(self): self.io.seek(0); self.bit_shift = 0
8889 def align (self ): self .bit_shift = 0
8990 def seek (self , position , mode = SEEK_SET ):
9091 self .io .seek (position , mode )
91- if self .io .tell () and self .bit_shift :
92+ if self .io .tell ()!= 0 and self .bit_shift != 0 :
9293 self .io .seek (- 1 , SEEK_CUR )
93- self .last_byte = ord (self .io . read (1 ))
94+ self .last_byte = ord (self .read_basic (1 ))
9495
9596 def peek (self , length ):
9697 start ,last ,ret = self .cursor ,self .last_byte ,self .read_hex (length )
@@ -104,23 +105,23 @@ def peek(self, length):
104105 def read_byte (self ):
105106 """ Basic byte read """
106107 if self .bit_shift == 0 :
107- return ord (self .io . read (1 ))
108+ return ord (self .read_basic (1 ))
108109 else :
109110 return self .read (1 )[0 ]
110111
111112 def read_int (self , endian = LITTLE_ENDIAN ):
112113 """ int32 read """
113- chars = self .io . read (4 ) if self .bit_shift == 0 else self .read_chars (4 )
114+ chars = self .read_basic (4 ) if self .bit_shift == 0 else self .read_chars (4 )
114115 return struct .unpack (endian + 'I' , chars )[0 ]
115116
116117 def read_short (self , endian = LITTLE_ENDIAN ):
117118 """ short16 read """
118- chars = self .io . read (2 ) if self .bit_shift == 0 else self .read_chars (2 )
119+ chars = self .read_basic (2 ) if self .bit_shift == 0 else self .read_chars (2 )
119120 return struct .unpack (endian + 'H' , chars )[0 ]
120121
121122 def read_chars (self , length = 0 ):
122123 if self .bit_shift == 0 :
123- return self .io . read (length )
124+ return self .read_basic (length )
124125 else :
125126 return '' .join (chr (byte ) for byte in self .read (length ))
126127
@@ -240,7 +241,7 @@ def _make_mask(byte, bit_length, current=1):
240241 def read_range (self , start , end ):
241242 current = self .cursor
242243 self .io .seek (start )
243- ret = self .io . read (end - start )
244+ ret = self .read_basic (end - start )
244245 self .io .seek (current )
245246 return ret
246247
@@ -265,7 +266,7 @@ def shift(self, bits):
265266 #make sure there are enough bits left in the byte
266267 if new_shift <= 8 :
267268 if not bit_shift :
268- self .last_byte = ord (self .io . read (1 ))
269+ self .last_byte = ord (self .read_basic (1 ))
269270
270271 #using a bit_mask_array tested out to be 20% faster, go figure
271272 ret = (self .last_byte >> bit_shift ) & self .lo_masks [bits ]
@@ -294,7 +295,7 @@ def read(self, bytes=0, bits=0):
294295
295296 #check special case of byte-aligned reads, performance booster
296297 if self .bit_shift == 0 :
297- base = [ord (self .io . read (1 )) for byte in range (bytes )]
298+ base = [ord (self .read_basic (1 )) for byte in range (bytes )]
298299 if bits != 0 :
299300 return base + [self .shift (bits )]
300301 return base
@@ -319,7 +320,7 @@ def read(self, bytes=0, bits=0):
319320
320321 #Set up for the looping with a list, the bytes, and an initial part
321322 raw_bytes = list ()
322- prev , next = self .last_byte , ord (self .io . read (1 ))
323+ prev , next = self .last_byte , ord (self .read_basic (1 ))
323324 first = prev & hi_mask
324325 bit_count -= 8 - old_bit_shift
325326
@@ -351,7 +352,7 @@ def read(self, bytes=0, bits=0):
351352 bit_count -= 8
352353
353354 #Cycle down to the next byte
354- prev ,next = next ,ord (self .io . read (1 ))
355+ prev ,next = next ,ord (self .read_basic (1 ))
355356
356357 self .last_byte = next
357358 self .bit_shift = new_bit_shift
0 commit comments