def read_vlq(bytestream):
    """
    Give a bytestream, extract the leading Variable Length Quantity (VLQ).

    We have to do this as a stream, since we don't know how long a VLQ is
    until we observe its end.
    """
    d = b""
    v = 0
    while True:
        tmp = yield from bytestream.readexactly(1)
        d += tmp
        tmp = ord(tmp)
        v <<= 7
        v |= tmp & 0x7f

        if tmp & 0x80 == 0:
            break
    return v, d