Python - What is the most efficient way to generate padding?
bytes += "\0"*len_diff
should help
Couldn't you just use ljust()
to do the padding since we're dealing with string objects here?
bytes = f.read(self.chunksize)
if bytes:
bytes = bytes.ljust(self.chunksize, '\0')
try this.
bytes = "\0" * self.chunksize
rbytes = f.read(self.chunksize)
bytes[:len(rbytes)] = rbytes
or
bytes = f.read(self.chunksize)
bytes += "\0" * (self.chunksize - len(bytes))