import struct


def decode_BER_int_from_stream(reader):
    """
    Decode a BER-encoded integer from a stream and return the decoded value.
    Reads only enough bytes to complete the value.
    """
    value = struct.unpack("B", reader.read(1))[0] # Decode the first byte

    if value > 127:
        # Decode the extended value
        value = int(reader.read(value - 128).encode("hex"), 16)

    return value