Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add custom padding byte support #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions binary_reader/binary_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ def buffer(self) -> bytearray:
"""Returns the buffer as a bytearray."""
return bytearray(self.__buf)

def pad(self, size: int) -> None:
"""Pads the buffer by 0s with the given size and advances the buffer position.\n
def pad(self, size: int, paddingByte: int = 0) -> None:
"""Pads the buffer with the given byte (defaults to 0) with the given size and advances the buffer position.\n
Will advance the buffer position only if the position was at the end of the buffer.
"""
if self.__idx == self.size():
self.__idx += size

self.extend([0] * size)
self.extend([paddingByte] * size)

def align_pos(self, size: int) -> int:
"""Aligns the current position to the given size.\n
Expand Down