Arjen Nienhuis added the comment:
struct.pack does not work with variable length data. Something like:
b'{0:x}\r\n{1}\r\n'.format(len(block), block)
or
b'%x\r\n%s\r\n' % (len(block), block)
is not possible with struct.pack
--
__
Arjen Nienhuis added the comment:
> def chunk(block):
> return hex(len(block)).encode('ascii') + b'\r\n' + block + b'\r\n'
hex(10) returns '0xa' instead of 'a'.
> This doesn't need any format call, and describes adequatly how t
Arjen Nienhuis added the comment:
There are many binary formats that use ASCII numbers.
'HTTP chunking' uses ASCII mixed with binary (octets).
With 2.6 you could write:
def chunk(block):
return b'{0:x}\r\n{1}\r\n'.format(len(block), block)
With 3.0 you'd have