def create_file(path, size):
"""Create a file with random contents and a given size"""
print('Creating file: {} having a size of {} Bytes'.format(path, size))
t_start = time.time()
with open(path, mode='wb') as fp:
# Write integer number of blocks
data_left = size
for _ in range(size // DATA_BLOCK):
fp.write(os.urandom(DATA_BLOCK))
data_left -= DATA_BLOCK
# Write the remainder (if any)
if data_left > 0:
fp.write(os.urandom(data_left))
print('File created in {} sec.'.format(time.time()-t_start))
评论列表
文章目录