def load_blocks_from_checkpoints(checkpoints_path, start, end):
"""Load blocks from checkpoints"""
checkpoint_set = sbds.checkpoints.required_checkpoints_for_range(
path=checkpoints_path, start=start, end=end)
total_blocks_to_load = end - start
with fileinput.FileInput(
mode='r',
files=checkpoint_set.checkpoint_paths,
openhook=checkpoint_opener_wrapper(encoding='utf8')) as blocks:
blocks = toolz.itertoolz.drop(checkpoint_set.initial_checkpoint_offset,
blocks)
if total_blocks_to_load > 0:
with click.open_file('-', 'w', encoding='utf8') as f:
for i, block in enumerate(blocks, 1):
click.echo(block.strip().encode('utf8'), file=f)
if i == total_blocks_to_load:
break
else:
with click.open_file('-', 'w', encoding='utf8') as f:
for block in blocks:
click.echo(block.strip().encode('utf8'), file=f)
评论列表
文章目录