Last active
November 7, 2017 15:30
-
-
Save MichalMazurek/f10d069926d0d55e07f9a980ad411461 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env python | |
import fire | |
import random | |
import humanize | |
import sys | |
def make_large_file(file: str, size: int, random: bool=False) -> None: | |
""" | |
Create a file with random bytes | |
--file file path | |
--size number of megabytes to generate | |
--random flag to indicate if the data should be rundom or ones | |
""" | |
chunk_size = 104857 | |
pos = 0 | |
if random: | |
def chunk_generator(): | |
return bytearray([ | |
random.getrandbits(8) for _ in range(chunk_size)]) | |
else: | |
byte_1 = (1).to_bytes(1, 'big') | |
def chunk_generator(): | |
return byte_1*(int(chunk_size)) | |
with open(file, 'wb') as test_file: | |
for x in range(0, size*1048576, chunk_size): | |
sys.stdout.write(".") | |
if not pos % 50: | |
sys.stdout.write(humanize.naturalsize(x)+"\n") | |
sys.stdout.flush() | |
chunk = chunk_generator() | |
test_file.write(chunk) | |
pos += 1 | |
print("Done.") | |
if __name__ == "__main__": | |
fire.Fire(make_large_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment