ptrlib.binary.encoding.dump

Functions

hexdump(→ None)

Print (or append) a classic hexdump.

Module Contents

ptrlib.binary.encoding.dump.hexdump(data: str | bytes | bytearray | memoryview, base: int = 0, file: BinaryIO | None = None, *, color: bool = True, color_ascii: str = Color.BRIGHT_BLUE, color_nonascii: str = Color.BRIGHT_CYAN, color_null: str = Color.WHITE, collapse_repeats: bool = True, prefix: str = '', postfix: str = '') None[source]

Print (or append) a classic hexdump.

  • 16 bytes per line: hex bytes grouped 8+8, then ASCII gutter.

  • Repeated consecutive lines are collapsed to a single ‘*’ when collapse_repeats=True (default). Set it to False to show all lines.

  • If file is provided (binary stream), lines are appended to that file instead of being printed to stdout.

  • If color=True, both the HEX area and ASCII gutter are colored:
    • printable (0x20..0x7e): cyan

    • NUL (0x00): black/gray

    • others: standard (no color)

Parameters:
  • data – Bytes (or str; converted via str2bytes) to dump.

  • base – Starting offset shown at the left.

  • file – Binary file-like object to append lines to (opened for writing).

  • color – Enable colorized output (requires Color constants).

  • collapse_repeats – Collapse identical consecutive rows into a single ‘*’.

  • prefix – String prepended to each output line.

  • postfix – String appended to each output line.