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. Ifbytes
, it is the input byte chunk. IfNone
, it reads from the standard input.outfile (str or bytes) – Output data. If
str
, it is considered as the output file path. Ifbytes
, it is the output byte chunk. IfNone
, 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
orinclude
.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 switchesrevert
,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. Specifygroupsize
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 topostscript
orinclude
.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 toos.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
andpostscript
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 withoffset
added to file positions found in hexdump.iseek (int or str) – Starts at
iseej
bytes absolute (or relative) input offset. Withoutiseek
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.