import struct
import binascii


def make_chunk(type, data):
    """Create chunk with @type and chunk data @data.

    It will calculate length and crc for you. Return bytes.

    @type is str and @data is bytes.
    """
    out = struct.pack("!I", len(data))
    data = type.encode("latin-1") + data
    crc32 = binascii.crc32(data)
    out += data + struct.pack("!i", crc32)
    return out