'Read a chunk of data.'

def _read_segment_file(self, data, idx, fi, start, stop, cals, mult):

    from ..utils import _mult_cal_one
    dtype = '<f4'
    n_bytes = np.dtype(dtype).itemsize
    egi_info = self._raw_extras[fi]
    offset = (egi_info['header_sizes'][0] - n_bytes)
    n_channels = egi_info['n_channels']
    n_samples = egi_info['samples_block'][0]
    block_size = (n_samples * n_channels)
    data_offset = (((n_channels * start) * n_bytes) + offset)
    data_left = ((stop - start) * n_channels)
    egi_events = egi_info['egi_events'][:, start:stop]
    extra_samps = (start // n_samples)
    beginning = (extra_samps * block_size)
    data_left += (((data_offset - offset) // n_bytes) - beginning)
    if (len(egi_events) > 0):
        e_start = 0
    with open(self._filenames[fi], 'rb', buffering=0) as fid:
        fid.seek(int((((beginning * n_bytes) + offset) + (extra_samps * n_bytes))))
        sample_start = 0
        s_offset = (((data_offset // n_bytes) - beginning) // n_channels)
        while ((sample_start * n_channels) < data_left):
            flag = np.fromfile(fid, dtype=np.dtype('i4'), count=1)[0]
            if (flag == 1):
                header_size = np.fromfile(fid, dtype=np.dtype('i4'), count=1)[0]
                block_size = np.fromfile(fid, dtype=np.dtype('i4'), count=1)[0]
                fid.seek((header_size - (3 * n_bytes)), 1)
            block = np.fromfile(fid, dtype, block_size)
            block = block.reshape(n_channels, (-1), order='C')
            count = (data_left - (sample_start * n_channels))
            end = ((count // n_channels) + 2)
            if (sample_start == 0):
                block = block[:, s_offset:end]
                sample_sl = slice(sample_start, (sample_start + block.shape[1]))
            elif (count < block_size):
                block = block[:, :end]
            if (len(egi_events) > 0):
                e_chs = egi_events[:, e_start:(e_start + block.shape[1])]
                block = np.vstack([block, e_chs])
                e_start += block.shape[1]
            if (sample_start != 0):
                sample_sl = slice((sample_start - s_offset), ((sample_start - s_offset) + block.shape[1]))
            data_view = data[:, sample_sl]
            sample_start = (sample_start + n_samples)
            _mult_cal_one(data_view, block, idx, cals, mult)
