def to_chunks(readable, bufsize=1024):
    """Convert *readable*, which is any object supporting ``read()``
    (e.g. fileobjs) to a stream of non-empty ``bytes``.

    If *readable* has an ``__iter__`` method but not a ``read`` method,
    pass through as-is.
    """
    if hasattr(readable, '__iter__') and not hasattr(readable, 'read'):
        for chunk in readable:
            yield chunk
        return
    while True:
        chunk = readable.read(bufsize)
        if chunk:
            yield chunk
        else:
            return
