def chunk_encoding(chunks, chunk):
    '''Write a chunk::
        chunk-size(hex) CRLF
        chunk-data CRLF
    If the size is 0, this is the last chunk, and an extra CRLF is appended.
    '''
    chunks.extend(("%X\r\n" % len(chunk)).encode('utf-8'))
    chunks.extend(chunk)
    chunks.extend(CRLF)
Write a chunk::
        chunk-size(hex) CRLF
        chunk-data CRLF
    If the size is 0, this is the last chunk, and an extra CRLF is appended.