INNER CODE UNIT · Python

is_file_small_enough

fyoorer/ShadowClone · shadowclone.py:23

def is_file_small_enough(file_path):
    return os.path.getsize(file_path) < 5 * 1024 * 1024


def splitfile(infile, SPLIT_NUM):
    # from https://stackoverflow.com/questions/16289859/splitting-large-text-file-into-smaller-text-files-by-line-numbers-using-python
    lines_per_file = int(SPLIT_NUM)

    smallfile = None
    chunks = []
    with open(infile, 'r', encoding='utf8', errors='ignore') as bigfile:
        tempdir = tempfile.gettempdir()
        for lineno, line in enumerate(bigfile):
            if lineno % lines_per_file == 0:
                if smallfile:
                    smallfile.close()
                # small_filename = '/tmp/small_file_{}.txt'.format(lineno + lines_per_file)
                small_filename = os.path.join(tempdir, 'small_file_{}.txt'.format(lineno + lines_per_file))

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…