import struct


def read_vary(stream, data_size_type="B"):
    """!
    @brief Read variable length data from stream.

    @param stream Data stream.
    @param data_size_type Type of data size in Python's struct module representation.
    @return Data in byte array.
    """
    # Read data size
    data_size_size = struct.calcsize(data_size_type)
    data_size = struct.unpack(data_size_type, stream.read(data_size_size))[0]
    # Read data
    return bytearray(stream.read(data_size))