def chunks(iterable, n):
    """Yield iterable split into chunks.

    If 'n' is an integer, yield the iterable as n-sized chunks.
    If 'n' is a list of integers, yield chunks of sizes: n[0],
    n[1], ..., len(iterable) - sum(n)

    >>> from invenio_sipstore.archivers.utils import chunks
    >>> list(chunks('abcdefg', 3))
    ['abc', 'def', 'g']
    >>> list(chunks('abcdefg', [1, ]))
    ['a', 'bcdefg']
    >>> list(chunks('abcdefg', [1, 2, 3]))
    ['a', 'bc', 'def', 'g']
    """
    if isinstance(n, int):
        for i in range(0, len(iterable), n):
            yield iterable[i:i + n]
    elif isinstance(n, list):
        acc = 0
        if sum(n) < len(iterable):
            n.append(len(iterable))
        for i in n:
            if acc < len(iterable):
                yield iterable[acc:acc + i]
                acc += i
