def __init__(self, raw: io.RawIOBase, buffer_size: int = io.DEFAULT_BUFFER_SIZE, *, bar_kwargs: Dict[str, Any]): super().__init__(raw, buffer_size) file_size = os.fstat(raw.fileno()).st_size self.progress_bar = tqdm(total=file_size, **bar_kwargs)
def __init__(self, raw: io.RawIOBase, buffer_size: int = io.DEFAULT_BUFFER_SIZE, *, bar_fn: BarFn): super().__init__(raw, buffer_size) file_size = os.fstat(raw.fileno()).st_size self._read_bytes = 0 self.progress_bar = bar_fn(total=file_size)
def write_intf_packets(fd: io.RawIOBase, outq: MIOVQ, freeq: MIOVQ): logger.info("write_packets: from %s", outq.name) while True: m = outq.pop() mlen = m.len() n = os.writev(fd.fileno(), m.iov) if n != mlen: logger.error("write: bad write %d (mlen %d) on interface", n, mlen) if DEBUG: logger.debug("write: %d bytes on interface", n) # logger.debug("write: %d bytes (%s) on interface", n, binascii.hexlify(m.start[:8])) freeq.push(m)
def read_wad(f: io.RawIOBase): f.seek(0) header = f.read(256) if header[:4] != WAD_MAGIC: raise CommandError( f'File does not appear to be a Zwift WAD file, Expected ' f'magic: {WAD_MAGIC}, actual: {header[:4]}') body_size = struct.unpack('<I', header[248:252])[0] wad_size = 256 + body_size actual_size = os.fstat(f.fileno()).st_size if actual_size < wad_size: raise CommandError(f'Truncated wad file: header implies ' f'{wad_size} bytes but file is {actual_size} bytes') if actual_size > wad_size: warnings.warn( f'wad file is larger than header implies. expected size: ' f'{actual_size} bytes, actual size: {actual_size} bytes') entry_pointers = read_entry_pointers(f) return {'file': f, 'entry_pointers': entry_pointers}
def __init__(self, raw: RawIOBase) -> None: self._fd = raw.fileno()