'The meat of `Header.fromfile`; in a separate method so that
`Header.fromfile` itself is just responsible for wrapping file
handling.  Also used by `_BaseHDU.fromstring`.
``block_iter`` should be a callable which, given a block size n
(typically 2880 bytes as used by the FITS standard) returns an iterator
of byte strings of that block size.
``is_binary`` specifies whether the returned blocks are bytes or text
Returns both the entire header *string*, and the `Header` object
returned by Header.fromstring on that string.'

@classmethod
def _from_blocks(cls, block_iter, is_binary, sep, endcard, padding):

    actual_block_size = _block_size(sep)
    clen = (Card.length + len(sep))
    blocks = block_iter(actual_block_size)
    try:
        block = next(blocks)
    except StopIteration:
        raise EOFError()
    if (not is_binary):
        block = encode_ascii(block)
    read_blocks = []
    is_eof = False
    end_found = False
    while True:
        (end_found, block) = cls._find_end_card(block, clen)
        read_blocks.append(decode_ascii(block))
        if end_found:
            break
        try:
            block = next(blocks)
        except StopIteration:
            is_eof = True
            break
        if (not block):
            is_eof = True
            break
        if (not is_binary):
            block = encode_ascii(block)
    if ((not end_found) and is_eof and endcard):
        raise IOError('Header    missing    END    card.')
    header_str = ''.join(read_blocks)
    if (header_str and (header_str[(-1)] == '\x00')):
        if (is_eof and (header_str.strip('\x00') == '')):
            warnings.warn('Unexpected    extra    padding    at    the    end    of    the    file.        This    padding    may    not    be    preserved    when    saving    changes.', AstropyUserWarning)
            raise EOFError()
        else:
            warnings.warn('Header    block    contains    null    bytes    instead    of    spaces    for    padding,    and    is    not    FITS-compliant.    Nulls    may    be    replaced    with    spaces    upon    writing.', AstropyUserWarning)
            header_str.replace('\x00', '    ')
    if (padding and ((len(header_str) % actual_block_size) != 0)):
        actual_len = ((len(header_str) - actual_block_size) + BLOCK_SIZE)
        raise ValueError('Header    size    is    not    multiple    of    {0}:    {1}'.format(BLOCK_SIZE, actual_len))
    return (header_str, cls.fromstring(header_str, sep=sep))
