def write_length_block(fp, writer, fmt='I', padding=1, **kwargs):
    """
    Writes a block of data with a length marker at the beginning.

    Example::

        with io.BytesIO() as fp:
            write_length_block(fp, lambda f: f.write(b'\x00\x00'))

    :param fp: file-like
    :param writer: function object that takes file-like object as an argument
    :param fmt: format of the length marker
    :param padding: divisor for padding not included in length marker
    :return: written byte size
    """
    length_position = reserve_position(fp, fmt)
    written = writer(fp, **kwargs)
    written += write_position(fp, length_position, written, fmt)
    written += write_padding(fp, written, padding)
    return written
def write_length_block ( fp , writer , fmt = 'I' , padding = 1 , ** kwargs ) : length_position = reserve_position ( fp , fmt ) written = writer ( fp , ** kwargs ) written += write_position ( fp , length_position , written , fmt ) written += write_padding ( fp , written , padding ) return written
Writes a block of data with a length marker at the beginning.

    Example::

        with io.BytesIO() as fp:
            write_length_block(fp, lambda f: f.write(b'\x00\x00'))

    :param fp: file-like
    :param writer: function object that takes file-like object as an argument
    :param fmt: format of the length marker
    :param padding: divisor for padding not included in length marker
    :return: written byte size