Advanced usage



When you used autoreset=False option of Packer, pack() method doesn’t return packed bytes.

You can use bytes() or getbuffer() to get packed data.

bytes() returns bytes object. getbuffer() returns some bytes-like object. It’s concrete type is implement detail and it will be changed in future versions.

You can reduce temporary bytes object by using Unpacker.getbuffer().

packer = Packer(use_bin_type=True, autoreset=False)

packer.pack([1, 2])
packer.pack([3, 4])

with open('data.bin', 'wb') as f:

packer.reset()  # reset internal buffer