def __init__(self, pc, name=None): self.pos = 0 self.closed = True self.file_size = 0 self.pc = pc self.buffer = array.array('c') if name is not None: self.open(name) self.buffer_size = INITIAL_PCARDFILE_BUFFER self.buffer.fromstring(pcardext.read(self.name, 0, self.buffer_size))
def read(self, size): if size > 0: if self.pos + size < self.buffer_size: data = self.buffer[self.pos:self.pos + size].tostring() self.pos += size return data else: # Read some more in from the card to satisfy the request while self.pos + size >= self.buffer_size: self.buffer.fromstring( pcardext.read(self.name, self.buffer_size, INCREMENTAL_PCARDFILE_BUFFER)) self.buffer_size += INCREMENTAL_PCARDFILE_BUFFER return self.read(size)