Implement readSegment function.