xxd_core#

hexrec.xxd.xxd_core(infile=None, outfile=None, autoskip=False, bits=None, cols=None, ebcdic=False, endian=False, groupsize=None, include=False, length=None, linesep=None, offset=None, postscript=False, quadword=False, revert=False, oseek=None, iseek=None, upper_all=False, upper=False, oseek_zeroes=True)[source]#

Emulation of the xxd utility core.

Parameters:
  • infile (str or bytes) – Input data. If str, it is considered as the input file path. If bytes, it is the input byte chunk. If None, it reads from the standard input.

  • outfile (str or bytes) – Output data. If str, it is considered as the output file path. If bytes, it is the output byte chunk. If None, it writes to the standard output.

  • autoskip (bool) – Toggles autoskip. A single '*' replaces null lines.

  • bits (bool) – Switches to bits (binary digits) dump, rather than hexdump. This option writes octets as eight digits of ‘1’ and ‘0’ instead of a normal hexadecimal dump. Each line is preceded by a line number in hexadecimal and followed by an ASCII (or EBCDIC) representation. The argument switches revert, postscript, include do not work with this mode.

  • cols (int) – Formats cols octets per line. Max 256. Defaults: normal 16, include 12, postscript 30, bits 6.

  • ebcdic (bool) – Changes the character encoding in the right-hand column from ASCII to EBCDIC. This does not change the hexadecimal representation. The option is meaningless in combinations with revert, postscript or include.

  • endian (bool) – Switches to little-endian hexdump. This option treats byte groups as words in little-endian byte order. The default grouping of 4 bytes may be changed using groupsize. This option only applies to hexdump, leaving the ASCII (or EBCDIC) representation unchanged. The switches revert, postscript, include do not work with this mode.

  • groupsize (int) – Separates the output of every groupsize bytes (two hex characters or eight bit-digits each) by a whitespace. Specify groupsize 0 to suppress grouping. groupsize defaults to 2 in normal mode, 4 in little-endian mode and 1 in bits mode. Grouping does not apply to postscript or include.

  • include (bool) – Output in C include file style. A complete static array definition is written (named after the input file), unless reading from standard input.

  • length (int) – Stops after writing length octets.

  • linesep (bytes) – Line separator characters. If None, it defaults to os.linesep.encode().

  • offset (int) – Adds offset to the displayed file position.

  • postscript (bool) – Outputs in postscript continuous hexdump style. Also known as plain hexdump style.

  • quadword (bool) – Uses 64-bit addressing.

  • revert (bool) – Reverse operation: convert (or patch) hexdump into binary. If not writing to standard output, it writes into its output file without truncating it. Use the combination revert and postscript to read plain hexadecimal dumps without line number information and without a particular column layout. Additional Whitespace and line breaks are allowed anywhere.

  • oseek (int) – When used after revert reverts with offset added to file positions found in hexdump.

  • iseek (int or str) – Starts at iseej bytes absolute (or relative) input offset. Without iseek option, it starts at the current file position. The prefix is used to compute the offset. + indicates that the seek is relative to the current input position. - indicates that the seek should be that many characters from the end of the input. +- indicates that the seek should be that many characters before the current stdin file position.

  • upper_all (bool) – Uses upper case hex letters on address and data.

  • upper (bool) – Uses upper case hex letters on data only.

  • oseek_zeroes (bool) – Output seeking fills with zeros. Only affects outfile of bytesparse.base.MutableMemory.

Returns:

stream – The handle to the output stream.