Skip to content

Buffer

Buffer(padding=0, byteorder='little')

Create binary data incrementally.

PARAMETER DESCRIPTION
padding

byte value to use for padding

TYPE: int DEFAULT: 0

byteorder

byte order to use for multi-byte values

TYPE: str DEFAULT: 'little'

add_byte(byte, count=1)

Add one or more bytes to buffer.

PARAMETER DESCRIPTION
byte

byte value to add

TYPE: int

count

number of times to add byte

TYPE: int DEFAULT: 1

add_data(data, length=0, padding=None)

Add data to buffer, with optional padding.

PARAMETER DESCRIPTION
data

data to add (bytes or string)

TYPE: bytes | str

length

pad data to this length if it is shorter

TYPE: int DEFAULT: 0

padding

byte value to use for padding

TYPE: int | None DEFAULT: None

add_int(value, size, byteorder=None)

Add an integer of given size to buffer.

PARAMETER DESCRIPTION
value

integer value to add

TYPE: int

size

size of integer in bytes

TYPE: int

byteorder

override default byte order

TYPE: str | None DEFAULT: None

add_long(value, byteorder=None)

Add a long (4 bytes) to buffer.

PARAMETER DESCRIPTION
value

long value to add

TYPE: int

byteorder

override default byte order

TYPE: str | None DEFAULT: None

add_word(word, byteorder=None)

Add a word (2 bytes) to buffer.

PARAMETER DESCRIPTION
word

word value to add

TYPE: int

byteorder

override default byte order

TYPE: str | None DEFAULT: None

add_zeros(length)

Add given number of zero bytes to buffer.

PARAMETER DESCRIPTION
length

number of zero bytes to add

TYPE: int

clear()

Clear buffer contents.

output(file)

Write buffer contents to file.

PARAMETER DESCRIPTION
file

file object to write to

TYPE: IO[bytes]

pad(length, padding=None)

Pad buffer to given length.

PARAMETER DESCRIPTION
length

length of buffer after padding

TYPE: int

padding

padding byte

TYPE: int | None DEFAULT: None